我从这个网站学习后做了一个静态的例子: http://docs.telerik.com/kendo-ui/getting-started/web/treeview/overview
现在我想添加更多项目作为子菜单。如何添加子菜单已经是父菜单的子菜单。
这是我的小提琴:http://jsfiddle.net/CDAVZ/580/
$(document).ready(function()
{
$('#one').click(function(){
alert('one')
});
$('#two').click(function(){
alert('two')
});
$('#three').click(function(){
alert('three')
});
// If you want to disable showing the context menu when right clicking
// on the document, the code below would do the trick.
$(document).bind("contextmenu",function(e)
{
return false;
});
var $tree = $("#tree").kendoTreeView(
{
dragAndDrop: true,
select: function (event)
{
var $item = $(event.node);
console.log( $item );
alert( "selected" );
}
});
// Find the item you want to select...
var $selected = $('#selected');
var $treePath = $selected.parentsUntil($tree, "li");
var treeView = $tree.data('kendoTreeView');
// Expand the tree in order to show the selected item
treeView.expand( $treePath );
// Gotta make both calls...
treeView.select( $selected );
treeView.trigger( 'select', {node: $selected} );
});
答案 0 :(得分:0)
如果使用treeView对象追加值,则应该全部设置。第一个参数是要添加的对象,第二个参数是要添加到的对象。它需要jquery选择器项,因此以下内容将起作用。
$('#one').click(function(){
treeView.append({text: 'new item'}, $("li:contains('Item1') ul"));
});
jsfiddle:http://jsfiddle.net/CDAVZ/582/