javascript - 尝试将新节点附加到现有节点不适用于自定义架构

标签 javascript kendo-ui kendo-treeview

在使用 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/

相关文章:

javascript - Google Calendar API - 如何使用 JavaScript 创建快速添加事件?

javascript - 有没有办法在允许 Parse.com "near"查询的同时保护我的地理点?

angular - 剑道- Angular :How to represent list view of JSON object

jquery - 只能拖放 kendo ui 网格未锁定一侧的行

asp.net-mvc - Kendo Treeview 远程数据所有节点最初加载

javascript - Kendo UI 层次结构子架构

javascript - 试图遍历一个节点得到休息返回

javascript - 如何在Vue2中添加多类绑定(bind)

asp.net-mvc - 在 Kendo UI ASP.net MVC 中使用 ViewModel

javascript - Kendo UI : TreeView - Is there anyway to catch an event for when a node is added?