javascript - How can I generate kendo tree view from hierarchical data? AngularJS -


how can add data source kendo-tree-view data, id in case projectattachmentfolderid , parent id - projectattachementfolderparentid

var flatdata = [{ "projectattachmentfolderid": null, "projectattachementfolderparentid": -1, "projectattachmentfoldername": "root", "projectiattachmenthasuniquepermissions": 1, "projectiattachmentisfolder": 1, "cancreate": true, "candelete": true, "canread": true, "canupdate": true, "projectattachmentfolderid2": null, "projectiattachmentid": -1, "foldertype": null, "id": 0 },                 { "projectattachmentfolderid": 5112, "projectattachementfolderparentid": null, "projectattachmentfoldername": "dokumenty klienta", "projectiattachmenthasuniquepermissions": 1, "projectiattachmentisfolder": 1, "cancreate": true, "candelete": true, "canread": true, "canupdate": true, "projectattachmentfolderid2": null, "projectiattachmentid": 6161, "foldertype": 4, "id": 0 },                 { "projectattachmentfolderid": 5156, "projectattachementfolderparentid": null, "projectattachmentfoldername": "dokumenty klienta", "projectiattachmenthasuniquepermissions": 1, "projectiattachmentisfolder": 1, "cancreate": true, "candelete": true, "canread": true, "canupdate": true, "projectattachmentfolderid2": null, "projectiattachmentid": 6228, "foldertype": 4, "id": 0 },                 { "projectattachmentfolderid": 5157, "projectattachementfolderparentid": null, "projectattachmentfoldername": "test projekt", "projectiattachmenthasuniquepermissions": 1, "projectiattachmentisfolder": 1, "cancreate": true, "candelete": true, "canread": true, "canupdate": true, "projectattachmentfolderid2": null, "projectiattachmentid": 6230, "foldertype": 5, "id": 0 },                 { "projectattachmentfolderid": 5158, "projectattachementfolderparentid": 5157, "projectattachmentfoldername": "test2", "projectiattachmenthasuniquepermissions": 1, "projectiattachmentisfolder": 1, "cancreate": true, "candelete": true, "canread": true, "canupdate": true, "projectattachmentfolderid2": null, "projectiattachmentid": 6233, "foldertype": 1, "id": 0 },                 { "projectattachmentfolderid": 5159, "projectattachementfolderparentid": 5157, "projectattachmentfoldername": "test3", "projectiattachmenthasuniquepermissions": 1, "projectiattachmentisfolder": 1, "cancreate": true, "candelete": true, "canread": true, "canupdate": true, "projectattachmentfolderid2": null, "projectiattachmentid": 6235, "foldertype": 1, "id": 0 },                 { "projectattachmentfolderid": 5160, "projectattachementfolderparentid": 5157, "projectattachmentfoldername": "test4", "projectiattachmenthasuniquepermissions": 1, "projectiattachmentisfolder": 1, "cancreate": true, "candelete": true, "canread": true, "canupdate": true, "projectattachmentfolderid2": null, "projectiattachmentid": 6236, "foldertype": 1, "id": 0 },                 { "projectattachmentfolderid": 5161, "projectattachementfolderparentid": null, "projectattachmentfoldername": "testproj2", "projectiattachmenthasuniquepermissions": 1, "projectiattachmentisfolder": 1, "cancreate": true, "candelete": true, "canread": true, "canupdate": true, "projectattachmentfolderid2": null, "projectiattachmentid": 6237, "foldertype": 5, "id": 0 },                 { "projectattachmentfolderid": 5162, "projectattachementfolderparentid": 5161, "projectattachmentfoldername": "dokumenty projektowe", "projectiattachmenthasuniquepermissions": 1, "projectiattachmentisfolder": 1, "cancreate": true, "candelete": true, "canread": true, "canupdate": true, "projectattachmentfolderid2": null, "projectiattachmentid": 6238, "foldertype": 1, "id": 0 },                 { "projectattachmentfolderid": 5163, "projectattachementfolderparentid": 5162, "projectattachmentfoldername": "flebok", "projectiattachmenthasuniquepermissions": 1, "projectiattachmentisfolder": 1, "cancreate": true, "candelete": true, "canread": true, "canupdate": true, "projectattachmentfolderid2": null, "projectiattachmentid": 6239, "foldertype": 1, "id": 0 },                 { "projectattachmentfolderid": 5164, "projectattachementfolderparentid": 5163, "projectattachmentfoldername": "dokumenty robocze", "projectiattachmenthasuniquepermissions": 1, "projectiattachmentisfolder": 1, "cancreate": true, "candelete": true, "canread": true, "canupdate": true, "projectattachmentfolderid2": null, "projectiattachmentid": 6240, "foldertype": 1, "id": 0 },                 { "projectattachmentfolderid": 5165, "projectattachementfolderparentid": 5157, "projectattachmentfoldername": "dokumenty projektowe", "projectiattachmenthasuniquepermissions": 1, "projectiattachmentisfolder": 1, "cancreate": true, "candelete": true, "canread": true, "canupdate": true, "projectattachmentfolderid2": null, "projectiattachmentid": 6242, "foldertype": 1, "id": 0 },                 { "projectattachmentfolderid": 5166, "projectattachementfolderparentid": 5165, "projectattachmentfoldername": "flexbok", "projectiattachmenthasuniquepermissions": 1, "projectiattachmentisfolder": 1, "cancreate": true, "candelete": true, "canread": true, "canupdate": true, "projectattachmentfolderid2": null, "projectiattachmentid": 6243, "foldertype": 1, "id": 0 },                 { "projectattachmentfolderid": 5167, "projectattachementfolderparentid": 5166, "projectattachmentfoldername": "dokumenty finalne", "projectiattachmenthasuniquepermissions": 1, "projectiattachmentisfolder": 1, "cancreate": true, "candelete": true, "canread": true, "canupdate": true, "projectattachmentfolderid2": null, "projectiattachmentid": 6244, "foldertype": 2, "id": 0 },                 { "projectattachmentfolderid": 5168, "projectattachementfolderparentid": 5163, "projectattachmentfoldername": "dokumenty finalne", "projectiattachmenthasuniquepermissions": 1, "projectiattachmentisfolder": 1, "cancreate": true, "candelete": true, "canread": true, "canupdate": true, "projectattachmentfolderid2": null, "projectiattachmentid": 6248, "foldertype": 2, "id": 0 }];  vm.folders2 = processtable(flatdata, "projectattachmentfolderid", "projectattachementfolderparentid", -1); 

next convert flatdata herarchical folders vm.folders2. here function:

function processtable(data, idfield, foreignkey, rootlevel) {                 var hash = {};                  (var = 0; < data.length; i++) {                     var item = data[i];                     var id = item[idfield];                     var parentid = item[foreignkey];                      hash[id] = hash[id] || [];                     hash[parentid] = hash[parentid] || [];                      item.items = hash[id];                     hash[parentid].push(item);                 }                  return hash[rootlevel];             } 

next try data hierarchicaldatasource.

$scope.treenewdatasource = new kendo.data.hierarchicaldatasource({                 data: vm.folders2,                 schema: {                     model: {                         id: "projectattachmentfolderid",                         fields: {                             projectattachmentfolderid:{  type: "number" },                             projectattachementfolderparentid: { type: "number" },                             projectattachmentfoldername: { type: "string" },                             projectiattachmenthasuniquepermissions: { type: "number" },                             projectiattachmentisfolder: { type: "number" },                             cancreate: { type: "boolean" },                             candelete: { type: "boolean" },                             canread: { type: "boolean" },                             canupdate: { type: "boolean" },                             projectattachmentfolderid2: { type: "number" },                             projectiattachmentid: { type: "number" },                             foldertype: { type: "number" },                             id: { type: "number" }                         },                         haschildren: function (x) {                             var id = x.projectattachmentfolderid;                             //alert('id:' + x.id + ' parent: ' + x.parent);                             var flatdata = vm.folders2;                             (var = 0; < flatdata.length; i++) {                                 if (flatdata[i].projectattachementfolderparentid == id) {                                     return true;                                 }                             }                             return false;                         }                     }                 }             });     

at lest add treeview in cshtml:

<div kendo-tree-view="tree" class="hasmenu" id="tree" k-data-source="treedata">             <span class="hasmenu treeviewspans" k-template id="{{dataitem.projectattachmentfolderid}}" projectattachmentfolderid="{{dataitem.projectattachmentfolderid}}" projectattachementfolderparentid="{{dataitem.projectattachementfolderparentid}}">                 {{dataitem.projectattachmentfoldername}}             </span>         </div> 

when dont have nodes in tree...what wrong ?

first see errors :

            var dstree = new kendo.data.hierarchicaldatasource({             data: vm.folders2,             schema: {                 model: {                     id: "projectattachmentfolderid",                     children: "items",                     haschildren: "haschildren"                 }             }         }); 

look @ prop: haschildren , it's children , not fields


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -