jsTree-按需通过Ajax加载子节点

jsTree-按需通过Ajax加载子节点,第1张

jsTree-按需通过Ajax加载子节点

Irishka向我指出了正确的方向,但并不能完全解决我的问题。我在弄弄她的答案,然后想到了这个。仅为了清楚起见,使用了两个不同的服务器功能。第一个列出了顶层的所有产品,第二个列出了给定productid的所有子级:

jQuery("#introspection_tree").jstree({    "plugins" : ["themes", "json_data", "ui"],    "json_data" : {        "ajax" : { "type": 'GET', "url": function (node) {     var nodeId = "";     var url = ""     if (node == -1)     {         url = "http://localhost/introspection/introspection/product/";     }     else     {         nodeId = node.attr('id');         url = "http://localhost/introspection/introspection/children/" + nodeId;     }     return url; }, "success": function (new_data) {     return new_data; }        }    }});

从函数返回的json数据是这样的(注意state =每个节点中的close状态):

[  {    “ data”:“套件1”,    “ attr”:{      “ id”:“ 1”    },    “ state”:“关闭”  },  {    “数据”:“ KPCM 049”,    “ attr”:{      “ id”:“ 4”    },    “ state”:“关闭”  },  {    “ data”:“ Linux BSP”,    “ attr”:{      “ id”:“ 8”    },    “ state”:“关闭”  }]

不需要静态数据,该树现在在每个级别上都是完全动态的。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5002178.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-14
下一篇 2022-11-14

发表评论

登录后才能评论

评论列表(0条)

保存