jsTree无法从AJAX调用加载根节点

编程入门 行业动态 更新时间:2024-10-27 22:22:22
本文介绍了jsTree无法从AJAX调用加载根节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我无法使用下面的jsTree加载初始根节点: 数据在服务器上,并且必须通过AJAX为选定的每个节点购买".我还想使用一个复选框并获取所选节点的所有父节点的值.

I am not able to load the initial root nodes using jsTree below: the data is on a server and has to be 'bought in' via AJAX for each node selected. I also want to use a checkbox and get value of all parent nodes of a selected node.

当前的主要问题是:我无法列出根节点....

main issue right now is: I am not able to list the root nodes....

//jsTree $('#testTree').jstree({ 'core' : { 'data' : { 'url' : function (node) { return node.id === '#' ? '/cgi-bin/test.pl' //url for root nodes '/cgi-bin/test.pl?nodes-in-selected-heirarchy'; //url for children nodes }, 'data' : function (node) { console.log('node.id='+node.id); return { 'id' : node.id }; } } } });

显示的只是一个文件夹图标.

all that this shows is a folder icon.

我从服务器获取的JSON是:

{"5":"summer","8":"vacation","2":"2015","3":"2014","4":"2013","6":"winter","1":"2016","7":"birthday"}

它是key:value,格式.

这是一个新的修改后的代码:即使这样也不起作用...

Here is a new modified code: even this does not work ...

$('#test').jstree({ 'core': { 'data':{ //this is the data provided to the jsTree to draw the tree. 'url': function( node ){ if( node.id === '#' ){ console.log('1'); return "/cgi-bin/test.pl"; } else { console.log('2'); return "/cgi-bin/test.pl?jsTreeParentKey=" + node.data( "key" ); } }, 'data': function(node) { //the data sent to the server console.log('node.id='+node.id); return { 'id': node.id, 'xyz': 'value_xyz' //extra set of param=value sent to server }; }, 'success': function (retData) { data = []; for( indx in retData ){ var value = retData[indx] console.log('indx=i'+indx+', value='+value); node = { 'id' : 'i'+indx, 'text' : value, 'icon' : '/', //'metadata' : value, 'state' : {'opened' : false} //'state' : 'closed' } data.push( node ); } return data; } // "check_callback" : true } }, "checkbox" : { "keep_selected_style" : false }, "plugins" : [ "checkbox","json_data" ] });

我在日志中得到了

1 <---- from URL node.id=# <----from param sent indx=i1, value=2016 indx=i2, value=2015 indx=i3, value=2014 indx=i4, value=2013 indx=i5, value=summer indx=i6, value=winter indx=i7, value=birthday indx=i8, value=vacation

推荐答案

您的数据格式(从服务器返回的JSON)不是必需的jsTree格式.至少在每个节点上都包含一个text属性.

Your data format (the JSON you return from the server) is not in the required jsTree format. At least include a text property on each of your nodes.

这是详细的文档: github/vakata/jstree#the-required-json-format

Here are the detailed docs: github/vakata/jstree#the-required-json-format

更多推荐

jsTree无法从AJAX调用加载根节点

本文发布于:2023-10-29 12:53:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539742.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:节点   加载   jsTree   AJAX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!