KendoUI undefined Node issue when trying to add to root parent node

痞子三分冷 提交于 2019-12-13 01:23:30

问题


I have seen other questions with the same issue , the data seems the be the issue most of the time.

I did create a jsfiddle http://jsfiddle.net/gwvoqns8/

(always keep in mind that http has to be used, and not https )

that should demonstrate the problem

  1. I want to have whatever is typed into the text box to display as another named node of whatever name...
  2. The code I'm using seems to enforce me to selected an existing parent node and i do not want that.

Its a bit annoying why it is saying "undefined"

$("#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');
    }
});

回答1:


Try this:

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);
});



回答2:


I was noticing that you could just do this

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

However, OP answer would be better as then you will have the ability to add to children nodes if you wanted to, even though so said you didn't want to.

cheers



来源:https://stackoverflow.com/questions/35949967/kendoui-undefined-node-issue-when-trying-to-add-to-root-parent-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!