3

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

它工作正常,但现在我想使用id.

我在这里找到了一些代码,但它不适用于我的代码:

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

我还在 Kendo 网站上找到了这段代码,它可能会有所帮助:

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

1 回答 1

1

你能换个试试吗

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

和你的第二部分

var dataSource = treeview.dataSource;
var dataItem = dataSource.get(4); // find item with id = 4
var $selected = treeview.findByUid(dataItem.uid);
于 2013-07-11T18:39:59.593 回答