easy-ui树懒加载——jquery动态增加节点
主要是增加:onClick方法
$("#resourceTree").tree({
url: $("#m_endpoint").val() + "/user/getResource",
valueField: 'id',
textField: 'text',
animate: true,
collapsible: true,
// checkbox: true, //是否有复选框
// lines: true, // 是否有线
onLoadSuccess: function (node, data) {
},
onClick: function (node) {
$.post(
"/api/user/getResource?pid="+node.id,
function (json) {
$('#resourceTree').tree('append', {
parent: node.target,
data: json
});
}, "json");
}
});
返回值示例:
[{"id":"0","text":"数据门户","pid":"0","url":"/","children":[{"id":"1","text":"一级菜单","pid":"0","url":"/one","children":[{"id":"4","text":"一级二菜单1","pid":"1","url":"/one/code","children":[]},{"id":"5","text":"一级二菜单2","pid":"1","url":"/one/projects","children":[]}]},{"id":"2","text":"二级菜单","pid":"0","url":"/two","children":[{"id":"9","text":"二级2菜单1","pid":"2","url":"/two/status","children":[]},{"id":"10","text":"二级2菜单2","pid":"2","url":"/two/ins","children":[]},{"id":"11","text":"二级2菜单3","pid":"2","url":"/two/service","children":[]}]},{"id":"3","text":"三级菜单","pid":"0","url":"/three","children":[{"id":"18","text":"三级2菜单1","pid":"3","url":"/three/import","children":[]},{"id":"23","text":"三级2菜单3","pid":"3","url":"/three/log","children":[]},{"id":"27","text":"三级2菜单2","pid":"3","url":"/one/menu2","children":[]}]}]}]