EasyUI Tree添加节点

创建foods tree
首先,我们创建foods tree,代码像这样:
<div style="200px;height:auto;border:1px solid #ccc;">

    <ul id="tt" class="easyui-tree" url="tree_data.json"></ul>

</div>

注意,tree组件被定义在UL标记,tree节点数据载入tree_data.json。

得到父节点
我们点击节点以选择fruit节点,我们添加一些fruits数据。调用getSelected方法来得到节点handle。
var node = $('#tt').tree('getSelected');

getSelect方法的返回值是一个js对象,包括id,text,attributes和target属性。target属性是DOM对象,引用了被选择的节点,使用append方法添加节点。
添加节点:
var node = $('#tt').tree('getSelected');

if (node){

    var nodes = [{

        "id":13,

        "text":"Raspberry"

    },{

        "id":14,

        "text":"Cantaloupe"

    }];

    $('#tt').tree('append', {

        parent:node.target,

        data:nodes

    });

}

当我们添加一些fruits,可以看到:
原文地址:https://www.cnblogs.com/huangf714/p/5911796.html