1.前端tree绑定时,使用onBeforeExpand事件:当节点展开时触发加载子节点,自动会向服务端发送请求:url为绑定url,参数为当前节点id
this.tree = {
method: 'GET',
url: self.urls.queryCatalog,
queryParams: ko.observable(),
animate:true,
lines: true,
showLoading:true,
loadFilter: function (d) {
var list = utils.filterProperties(d, ['KEYFIELDNAME as id', 'PARENTFIELDNAME as pid', 'CATALOG_NAME as text']);
//将数据转换成tree绑定需要的格式
var treeData = utils.toTreeDataCollapse(list, "id", "pid", "children");
return treeData;
},
onSelect: function (node) {
self.Catalog(node.id);
},
onBeforeExpand: function (node) {
}
};
2.后台定义2个方法:一个加载初始节点,一个加载子节点