填充kendo树视图对话框的问题:仅填充根节点

时间:2017-11-28 12:11:57

标签: kendo-treeview kendo-datasource

尝试使用JSON数据填充kendo treeview时,我遇到了一些困难。我的剑道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视图仅填充第一层级中的元素 - 而不是其子元素。

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"
  }]
}]

我做错了什么想法? 感谢

1 个答案:

答案 0 :(得分:0)

我发现了问题 - JSON不正确。两者都扩大了#34;和" hasChildren"需要布尔属性。因此,值不是"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
  }]
}]