我正在使用Kendo TreeList。我使用Django TreeBeard的Adjacency List数据结构在数据库中有一个数据结构。对于树形图,由于数据是嵌套的,我创建平面对象并将它们放入数组中。这很好用,但是treelist不会刷新数据。
对象结构与父对象结构相同,但子节点不显示。
这是我的代码。
JSON:PARENT NODE
{"id": 26, "tgtWeight": 0.0, "currWeight": 0.0, "hasChildnode": true, "ext_model_id": 8, "parent": null, "SSM": {"id": 8, "securitySelectionModelName": "ssm8", "userCreatedModel": "[{\"classificationName\":\"ssm8\",\"id\":8,\"hasChildNode\":true,\"child\":[{\"classificationName\":\"MBS\",\"id\":14,\"hasChildNode\":true,\"child\":[{\"classificationName\":\"Common Stock\",\"id\":15,\"hasChildNode\":false}]}]}]", "classificationNames": []}, "classificationNameNode": null}
JSON CHILD NODE
[{"id": 27, "tgtWeight": 0.0, "currWeight": 0.0, "hasChildnode": true, "ext_model_id": 14, "parent": {"id": 26, "tgtWeight": 0.0, "currWeight": 0.0, "hasChildnode": true, "ext_model_id": 8, "parent": null, "SSM": 8, "classificationNameNode": null}, "SSM": {"id": 8, "securitySelectionModelName": "ssm8", "userCreatedModel": "[{\"classificationName\":\"ssm8\",\"id\":8,\"hasChildNode\":true,\"child\":[{\"classificationName\":\"MBS\",\"id\":14,\"hasChildNode\":true,\"child\":[{\"classificationName\":\"Common Stock\",\"id\":15,\"hasChildNode\":false}]}]}]", "classificationNames": []}, "classificationNameNode": {"id": 14, "classificationLevel": 2, "classificationName": "MBS", "hasChildNode": false, "parent": 2}}]
JAVASCRIPT
$(document).ready(function () {
var id = {{ id }};
var dataSource = new kendo.data.TreeListDataSource({
transport: {
read: {
url: "../getModelTargetWeights?SSM_id="+id,
dataType: "json"
}
},
schema: {
parse: function(response) {
NodeArray=[];
if (response.length == undefined) {
var node = {
id: response.id,
currWeight: response.currWeight,
tgtWeight: response.tgtWeight,
hasChildren: response.hasChildnode,
parentId: response.parent,
ext_model_id: response.ext_model_id,
securitySelectionModelName: response.SSM.securitySelectionModelName,
classificationNameNode: response.classificationNameNode
};
NodeArray.push(node);
} else {
for (var i=0; i < response.length; i++){
var node = {
id: response[i].id,
currWeight: response[i].currWeight,
tgtWeight: response[i].tgtWeight,
hasChildren: response[i].hasChildnode,
parentId: response[i].parent.ext_model_id,
ext_model_id: response[i].ext_model_id,
securitySelectionModelName: response[i].SSM.securitySelectionModelName,
classificationNameNode: response[i].classificationNameNode.classificationName
}
NodeArray.push(node);
}
}
return NodeArray;
},
model: {
id: "id",
parentId: "parentId",
fields: {
parentId: { field: "parentId", nullable: true },
securitySelectionModelName: "securitySelectionModelName",
classificationNameNode: "classificationNameNode",
tgtWeight: { field: "tgtWeight", nullable: true },
hasChildren: { type: "boolean", field: "hasChildren" }
}
}
}
});
$("#treeList").kendoTreeList({
dataSource: dataSource,
editable: true,
height: 540,
columns: [
{ field: "securitySelectionModelName", title: "Model Name" },
{ field: "classificationNameNode", title: "Classification" },
{ field: "tgtWeight", title: "Target" }
],
});
dataSource.read();
});
</script>