javascript - json 值的 jstree 给出了一些错误

标签 javascript json jstree

我的 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 };
            }
          }
        }
    });

关于javascript - json 值的 jstree 给出了一些错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32600994/

相关文章:

javascript - 高度自动 - 调整浏览器大小时显示隐藏内容

javascript - 如何处理 Vue.js 中模板标签中不保证存在的对象属性?

JavaScript 关联数组到 JSON

javascript - JQuery JsTree : jstree is not rendering properly in browser

php - 将自定义类添加到 jstree

javascript - 使用 jsTree XML 模块

javascript - 查明某个 id 本身是否包含特定文本部分

javascript - 类声明中未定义 super 方法

c# - 将 json 转换为 c# 对象列表

c# - 如何将Json对象转换为Web服务中的自定义类对象?