zoukankan      html  css  js  c++  java
  • artTemplate子模板include

    art.Template:https://github.com/aui/art-template

    下面来实现利用模版来实现递归调用生成tree

    <script type="text/html" id="list1">
    
        <div style="padding:10px;">
            <div id="id_{{id}}">
                <span>{{title}}</span>
                <span>{{content}}</span>
                {{if children.length>0}}
    
                {{each children as node2}}
                {{include 'list1' node2}}
                {{/each}}
    
                {{/if}}
            </div>
        </div>
    
    </script>
    <script type="text/javascript">
    
        var data = {
            "id": "00000",
            "title": "标题0",
            "content": "标题0",
            "children": [
                {
                    "id": "111111",
                    "title": "标题1",
                    "content": "标题1",
                    "children": [
                        {
                            "id": "22222",
                            "title": "标题2",
                            "content": "标题2",
                            "children": [
                                {
                                    "id": "333333",
                                    "title": "标题3",
                                    "content": "标题3",
                                    "children": []
                                }
                            ]
                        }
                    ]
                },
                {
                    "id": "55555",
                    "title": "标题5",
                    "content": "标题5",
                    "children": [
                        {
                            "id": "66666",
                            "title": "标题6",
                            "content": "标题6",
                            "children": [
                                {
                                    "id": "7777777",
                                    "title": "标题7",
                                    "content": "标题7",
                                    "children": []
                                }
                            ]
                        }
                    ]
                }
            ]
    
    
        }
    
    
        var treeHTML = template("list1", data);
    
        $("body").append(treeHTML);
    
       
    
    
    </script>

    生成的结果图如下:

     不过我发现如果用ul标签来实现的话会出现li不能准确的被追加到children的ul里面不知道是什么原因,如果您有不同的看法欢迎评论交流。

    技术交流QQ群:15129679

  • 相关阅读:
    No module named cv2 报错处理
    CentOS 7自动以root身份登录GNOME桌面
    OpenVINO在linux下安装
    openvino资源
    electron-builder打包跳过publish
    Electron基础
    druid socket timeout超时15分钟(转载)
    第六次作业
    C语言感悟
    第五次作业
  • 原文地址:https://www.cnblogs.com/yeminglong/p/7338235.html
Copyright © 2011-2022 走看看