Below you can see the pertinent code. when I try to append a new node in the tree it's always "undefined" when I check $("#appendNodeText").val() it does have the correct value. What am I missing?
@(Html.Kendo().TreeView()
.Name("treeview")
//.TemplateId("treeview-template")
.HtmlAttributes(new { @class = "col-md-6", id = "treeview" })
.DataTextField("Title")
.DataImageUrlField("Image")
.DataSource(dataSource => dataSource
.Read(read => read
.Action("Categories", "DisplayArticle")
)
)
.Events(events => events
.Select("onSelect")
)
)
<li>
<input id="appendNodeText" value="Node" class="k-textbox" />
<button class="k-button" id="appendNodeToSelected">Append node</button>
</li>
var treeview = $("#treeview").data("kendoTreeView"),
handleTextBox = function (callback) {
return function (e) {
if (e.type != "keypress" || kendo.keys.ENTER == e.keyCode) {
callback(e);
}
};
};
var append = handleTextBox(function (e) {
//var treeview = $("#treeview").data("kendoTreeView")
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({
Name: $("#appendNodeText").val(),
id: $("#appendNodeText").val(),
text: $("#appendNodeText").val()
}, selectedNode);
});
$("#appendNodeToSelected").click(append);
@(Html.Kendo().TreeView()
.Name("treeview")
//.TemplateId("treeview-template")
.HtmlAttributes(new { @class = "col-md-6", id = "treeview" })
.DataTextField("Title")
.DataImageUrlField("Image")
.DataSource(dataSource => dataSource
.Read(read => read
.Action("Categories", "DisplayArticle")
)
)
.Events(events => events
.Select("onSelect")
)
)
<li>
<input id="appendNodeText" value="Node" class="k-textbox" />
<button class="k-button" id="appendNodeToSelected">Append node</button>
</li>
var treeview = $("#treeview").data("kendoTreeView"),
handleTextBox = function (callback) {
return function (e) {
if (e.type != "keypress" || kendo.keys.ENTER == e.keyCode) {
callback(e);
}
};
};
var append = handleTextBox(function (e) {
//var treeview = $("#treeview").data("kendoTreeView")
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({
Name: $("#appendNodeText").val(),
id: $("#appendNodeText").val(),
text: $("#appendNodeText").val()
}, selectedNode);
});
$("#appendNodeToSelected").click(append);