Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 使用id展开剑道ui树节点_Jquery_Kendo Ui_Kendo Treeview - Fatal编程技术网

Jquery 使用id展开剑道ui树节点

Jquery 使用id展开剑道ui树节点,jquery,kendo-ui,kendo-treeview,Jquery,Kendo Ui,Kendo Treeview,我正在使用绑定到远程数据创建剑道ui树 我是剑道ui的新手,如果我使用下面的代码来扩展树,它会工作得很好 var treeview = $("#treeview").data("kendoTreeView"); // expand all nodes treeview.expand(".k-item"); 当我尝试使用id时,它会给我未定义的错误 代码是 var treeview = $("#treeview").data("kendoTreeView"); // expand the nod

我正在使用绑定到远程数据创建剑道ui树

我是剑道ui的新手,如果我使用下面的代码来扩展树,它会工作得很好

var treeview = $("#treeview").data("kendoTreeView");
// expand all nodes
treeview.expand(".k-item");
当我尝试使用
id
时,它会给我未定义的错误

代码是

var treeview = $("#treeview").data("kendoTreeView");
// expand the node with id=3
treeview.expand(document.getElementById("3"));
//treeview.dataSource.view();
这是我的jquery代码

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

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

// my function to expand node using id it is called on my button click
function expand_me(){
    var treeview = $("#treeview").data("kendoTreeView");
    // expand the node with id=3
    treeview.expand(document.getElementById("3"));
}
我对此不太了解,但js fiddle无法扩展(因为我使用的是数据库),所以我创建了用于崩溃的演示代码


有朋友能告诉我哪里做错了吗???

您的JSFIDLE示例没有id为3的元素
document.getElementById(“3”)
返回
null

如果您从剑道数据源中知道要折叠的项的uid,则可以使用jQuery选择器查找具有匹配
数据uid
属性的项:

$("#treeview")
    .data("kendoTreeView")
    .collapse('.k-item[data-uid="a7e9f5fd-4c11-4e0f-bb16-ae335c70c73f"]');
或者,如果您是指树中的第三项:

$("#treeview")
    .data("kendoTreeView")
    .collapse($('.k-item').eq(2));

您能在JSFIDLE中共享吗?@Parse我正在取消外部文件以获取data@Parse这是倒塌的原因