您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

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

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”:“关闭”
  }
]

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

其他 2022/1/1 18:13:35 有635人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶