jtree for json值给出一些错误

jstree for json value is giving some error

本文关键字:错误 for json jtree      更新时间:2023-09-26

我的Json:

[{"id":1,"text":"ungrouped","icon":"/icons/Group_16x16.png",  
  "parent":0,"dashboard":null,"childrenList":null}]

我的jS:

// ajax demo
    $('#ajax_topo').jstree({
        'core' : {
          'data' : {
            'url' : './topology.json',
            'data' : function (node) {
              return { 'id' : node.id };
            }
          }
        }
    });

我的Html:

<h1>AJAX Topology demo</h1>
<div id="ajax_topo" class="demo"></div>

我得到这个

Error: Uncaught TypeError: Cannot read property 'children' of undefined

这是个Json数组。所以你必须在上面应用索引

node.id替换为node[0].id

$('#ajax_topo').jstree({
        'core' : {
          'data' : {
            'url' : './topology.json',
            'data' : function (node) {
              return { 'id' : node[0].id };
            }
          }
        }
    });