在使用 Kendo UI Web v2012.3.1114 时,我遇到的问题是我尝试使用通过对服务器的 AJAX 调用检索的节点对 TreeView 进行简单追加,失败并出现以下错误。
该节点的格式与正常读取函数返回的数据格式完全相同。
我已成功使用 data("kendoTreeView").insertBefore(...)
对于同一棵树并进行调用,但是当我尝试使用 data("kendoTreeView").append(. ..)
失败了。
错误消息:
Uncaught TypeError: Property 'data' of object # is not a function kendo.web.min.js:25
由于我必须能够为以前是叶子的节点创建新的子节点,因此我无法使用任何其他 API 来执行此操作。
我做了一个jsFiddle显示树的定义以及我想要做什么。我尝试引用 Kendo 网站上的工作示例,但似乎一旦我使用自定义架构,事情就会向南发展。
这是我正在使用的 jsFiddle 的代码:
function populateHierarchyTree(quotaSetID, columnID, treeDiv) {
var transport = {
read: {
url: '/Quota/QuotaHierarchy/GetQuotaHierarchyChildrenFromParent',
dataType: 'json',
data: { columnDefinitionID: columnID, quotaSetID: quotaSetID, batchSize:10 },
type: 'POST'
}
};
var schema = {
model: {
id: 'id',
hasChildren: 'hasChildren'
}
};
var dataSource = new kendo.data.HierarchicalDataSource({
transport: transport,
schema: schema
});
treeDiv.kendoTreeView({
loadOnDemand: true,
dataSource: dataSource,
dataTextField: "text",
});
}
// This function is called with a single node which contains the exact same structure returned from GetQuotaHierarchyChildrenFromParent used by the read. ParentElement could be anything.
function AddNode(node,parentElement,treeView){
treeView.append(node,parentElement);
}
最佳答案
如何选择parentElement
?您确定它是一个 kendoTreeView
节点吗?
试试这个:
treeView.append(node, parentElement.closest(".k-item"));
通过添加 .closest(".k-item");
我尝试找到的是 parentNode
最接近的 node
祖先。
关于javascript - 尝试将新节点附加到现有节点不适用于自定义架构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13955739/