django+easyUi 树展示

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zjl199303/article/details/85156351

代码如下所示:

<ul class="easyui-tree" id="tree"></ul>



$(function () {

    init()

});



function init(){

    tree()

}



function tree(){

    $("#tree").tree({

        // checkbox: true,

        url:'/treeJson/',

        method:'get',

        animate:true,

        formatter:function(node){

            var s = node.text;

            if (node.children){

                s += ' <span style=\'color:blue\'>('+ node.children.length +')</span>';

            }

            return s;

        },

        onClick : function (node) {

            if(node.attributes){

              console.log('自己添加的属性: 【URL】'+ node.attributes.url +',  【info】' + node.attributes.info);

               location.href = node.attributes.url

            }

        }

    });

}

问题描述:

1、按照上面代码,通过init再调tree, ajax请求多遍

解决办法:

因为 tree 树结构写在了 base 模板中,凡是打开页面通过 base 渲染,就会调用  tree 方法。

同时其他也通过 base 模板渲染页面的页面也会调用 tree方法。

猜你喜欢

转载自blog.csdn.net/zjl199303/article/details/85156351