kendo-treeview - 填充 Kendo Treeview 对话框的问题 : only root nodes are populated

标签 kendo-treeview kendo-datasource

我在尝试使用 JSON 数据填充 Kendo treeview 时遇到了一些困难。我的 Kendo treeview 只显示根元素而不是子元素。

简而言之,我在 js 中有以下内容:

   var featuremodel = getMetaContentByName("filterJson");

   var featuremodeljson = jQuery.parseJSON(featuremodel);
   console.log(featuremodeljson);

   var local = new kendo.data.HierarchicalDataSource({  
               data: featuremodeljson,  
               schema:{
                    model: {
                        id: "id",
                        children: "items"
                    }
            }

   });


   $("#treeview").kendoTreeView({
        dataSource:  featuremodeljson,
        dataTextField: "FullName",
        checkboxes: true,
        checkboxes: {
            checkChildren: true
          },
        loadOnDemand: false,      
    });

我可以在控制台中看到,
   console.log(featuremodeljson) 

这是一个有效的 Json。我可以看到元素层次结构。然而,kendo View 只填充第一层级的元素——而不是它们的子元素。

Json 是这样的:
 [{
   "id": "No Feature",
   "FullName": "No Feature",
   "expanded": "true",
   "hasChildren": "true",
   "items": [ {
       "id": "Feature0",
       "FullName": "Feature0",
       "expanded": "true",
       "hasChildren": "true"
     }]
 },
{
   "id": "Sensors",
   "FullName": "Sensors",
   "expanded": "true",
   "hasChildren": "true",
   "items": [{
       "id": "Feature1",
       "FullName": "Feature1",
       "expanded": "true",
       "hasChildren": "true"
  }]
},  
 {
   "id": "Warnings",
   "FullName": "Warnings",
   "expanded": "true",
   "hasChildren": "true",
   "items": [ {
       "id": "Feature2",
       "FullName": "Feature2",
       "expanded": "true",
       "hasChildren": "true"
    }]
  },  
  {
   "id": "Languages",
   "FullName": "Languages",
   "expanded": "true",
   "hasChildren": "true",
   "items": [ {
       "id": "Feature3",
       "FullName": "Feature3",
       "expanded": "true",
       "hasChildren": "true"
  }]
}]

关于我做错了什么的任何想法?
谢谢

最佳答案

我发现了问题 - JSON 不正确。 “expanded”和“hasChildren”都需要 bool 属性。因此,这些值不是 "true" 而是 true

Json 应该是这样的:

[{
   "id": "No Feature",
   "FullName": "No Feature",
   "expanded": true,
   "hasChildren": true,
   "items": [ {
       "id": "Feature0",
       "FullName": "Feature0",
       "expanded": true,
       "hasChildren": true
     }]
 },
{
   "id": "Sensors",
   "FullName": "Sensors",
   "expanded": true,
   "hasChildren": true,
   "items": [{
       "id": "Feature1",
       "FullName": "Feature1",
       "expanded": true,
       "hasChildren": true
  }]
}]

关于kendo-treeview - 填充 Kendo Treeview 对话框的问题 : only root nodes are populated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47531340/

相关文章:

kendo-ui - 在 TreeViewOptions 的复选框的 Kendo ui 模板中使用参数

javascript - Kendo UI TreeView 复选框全选

javascript - 如何在剑道网格中手动设置列值

javascript - Kendo Grid 具有服务器过滤但客户端分页

javascript - 除非展开节点,否则 kendo treeview 数据源不会在 javascript 调试中显示子项

jquery - 即使没有子项,Kendo UI Treeview 也会显示扭曲

javascript - Kendo 网格 - 获取当前编辑行

javascript - Kendo UI Treeview - 绑定(bind)到本地数据时更新复选框状态

javascript - Kendo-UI 数据源 "contains"过滤器不起作用