如何防止在kendo-knockout树视图中添加重复节点

时间:2013-10-31 15:08:18

标签: javascript knockout.js kendo-ui treeview

防止在kendo-knockout树中添加重复节点

    Before adding nodetext to root node i need to check the existance of nodetext
if same nodetext present then show valid message
OR get child node of selected rood(node) 
$("#appendNode").click(function () {
                            var selectedNode = treeview.select();
                            var nodeText = $("#txtnode").val();//node to insert
                            if (selectedNode.length == 0)
                               selectedNode = null;
                            if (nodeText == null || nodeText == "")
                               return;
                             /*  if(nodetext is exist in childnode of selectedNode)
                                      valid message
                                 else
                                     add node to root
                              */
                            treeview.append({ text: nodeText }, selectedNode);
                        });

1 个答案:

答案 0 :(得分:1)

使用filterByText方法查明nodetext已存在  ``http://docs.kendoui.com/api/web/treeview

<div id="treeview"></div>
<script>
    $("#treeview").kendoTreeView({
    dataSource: [
        { text: "foo" },
        { text: "bar" }
    ]
    });

    var treeview = $("#treeview").data("kendoTreeView");
    // find the node with text "foo"
    var foo = treeview.findByText("foo");
    console.log(foo);
</script>

如果对树视图数据使用id

,也可以使用findByUid