javascript - 尝试添加到根父节点时出现 KendoUI 未定义节点问题

标签 javascript jquery kendo-ui treeview kendo-treeview

我见过其他有同样问题的问题,数据似乎是大多数时候的问题。

我确实创建了一个jsfiddle http://jsfiddle.net/gwvoqns8/

(始终记住必须使用 http,而不是 https )

这应该能说明问题

  1. 我希望在文本框中输入的任何内容都显示为任何名称的另一个命名节点...
  2. 我使用的代码似乎强制我选择现有的父节点,但我不希望这样。

为什么它说“未定义”有点烦人

$("#addTopLevel").click(function () {
    console.log('in this');
    if (treeview.select().length) {
        console.log('1');
        treeview.append({
            text: $("#appendNodeText").val()
        }, treeview.select());
    } else {
        //alert("please select tree node");
        console.log('2');
    }
});

最佳答案

试试这个:

var ds = new kendo.data.HierarchicalDataSource({
    data: [
        {"Id":1,"ReportGroupName":"Standard Reports","ReportGroupNameResID":null,"SortOrder":1},
        {"Id":2,"ReportGroupName":"Custom Reports","ReportGroupNameResID":null,"SortOrder":2},
        {"Id":3,"ReportGroupName":"Retail Reports","ReportGroupNameResID":null,"SortOrder":3},
        {"Id":4,"ReportGroupName":"Admin Reports","ReportGroupNameResID":null,"SortOrder":5},
        {"Id":5,"ReportGroupName":"QA Reports","ReportGroupNameResID":null,"SortOrder":4}
    ]
});


var treeview = $("#treeview").kendoTreeView({
    dataSource: ds,
    dataTextField: "ReportGroupName",
    loadOnDemand: false
}).data("kendoTreeView");

treeview.expand(".k-item");

$("#addTopLevel").click(function(e) {
    var selectedNode = treeview.select();

    // passing a falsy value as the second append() parameter
    // will append the new node to the root group
    if (selectedNode.length == 0) {
        selectedNode = null;
    }

    treeview.append({
        ReportGroupName: $("#appendNodeText").val()
    }, selectedNode);
});

关于javascript - 尝试添加到根父节点时出现 KendoUI 未定义节点问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35949967/

相关文章:

jquery - Rails PJAX 和 Twitter Bootstrap 插件运行不佳

javascript - 试图涂黑可移动 div 之外的所有内容

javascript - 将 javascript datetime 转换为 C# 时出现解析错误

javascript - 在异步 ajax 请求之前运行函数

razor - 可编辑的详细信息模板 Kendo UI 网格

json - 从 KendoUI TreeView 获取当前数据

javascript - 更准确的顺时针顶点排序

javascript - XSS:这如何安全?

javascript - 获取对象节点的值 - javascript

javascript - map 颜色模式 "random"适用于 Google 地球但不适用于 Google map