使用id打开Kendo UI TreeView节点

时间:2013-06-07 07:13:36

标签: jquery ajax json kendo-ui kendo-treeview

我正在使用Kendo UI TreeView来生成我的树。这是tree documentation

它工作正常,但现在我想使用id扩展(打开)一个节点。

我找到了一些代码here,但它无法使用我的代码:

var serviceRoot = "search/treej.php";
homogeneous = new kendo.data.HierarchicalDataSource({
    transport: {
        read: {
            url: serviceRoot,
            dataType: "jsonp"
        }
    },
    schema: {
        model: {
            id: "entity_id",
            hasChildren: "child"
        }
    }
});

$("#treeview").kendoTreeView({
    checkboxes: {
        checkChildren: false
    },
    dataSource: homogeneous,
    dataTextField: "value"
});


var $tree = $("#treeview").kendoTreeView(
    {
        select: function (event)
        {
            var $item = $(event.node);
            console.log( $item );
            alert( "selected" );
        }
    });

var $selected = $('#4'); // here i am passing static values
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} );

我也在剑道网站上找到了这个代码,可能有所帮助:

var dataSource = treeview.dataSource;
var dataItem = dataSource.get(5); // find item with id = 5
var node = treeview.findByUid(dataItem.uid);

1 个答案:

答案 0 :(得分:1)

你能尝试替换

吗?
var $selected = $('#4');

与你的第二部分

var dataSource = treeview.dataSource;
var dataItem = dataSource.get(4); // find item with id = 4
var $selected = treeview.findByUid(dataItem.uid);