我已经看到了同样问题的其他问题,数据似乎是大多数时候的问题。
我确实创建了一个jsfiddle http://jsfiddle.net/gwvoqns8/
(始终牢记必须使用http,而不是https)
应该证明问题
它有点烦人,为什么它说" 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');
}
});
答案 0 :(得分:0)
试试这个:
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);
});
答案 1 :(得分:0)
我注意到你可以这样做
treeview.append({
ReportGroupName: $("#appendNodeText").val()
}, null);
然而,OP答案会更好,因为如果你愿意,你可以添加到子节点,即使这样说你不想这样做。
欢呼声