尝试添加到根父节点时,KendoUI未定义节点问题 [英] KendoUI undefined Node issue when trying to add to root parent node

查看:193
本文介绍了尝试添加到根父节点时,KendoUI未定义节点问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也见过相同问题的其他问题,大多数情况下数据似乎都是问题.

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

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

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

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

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

应该证明问题的地方

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

为什么说未定义"很烦人

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

推荐答案

尝试一下:

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

这篇关于尝试添加到根父节点时,KendoUI未定义节点问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆