似乎无法将节点添加到剑道UI树视图

Cannot seem to add Node to Kendo UI TreeView

本文关键字:UI 视图 添加 节点      更新时间:2023-09-26

>我试图将文本框中的节点添加到现有的树视图

输入

<input id="appendNodeText" value="Node" class="k-textbox">

按钮

<button type="button" class="btn btn-blue" id="addTopLevel">Add Top Level Menu</button>

JavaScript

 <script>
     // button handler
      $("#addTopLevel").click(append);
     handleTextBox = function (callback) {
         return function (e) {
            if (e.type != "keypress" || kendo.keys.ENTER == e.keyCode) {
               callback(e);
             }
        };
     };
     var append = handleTextBox(function (e) {
     var selectedNode = treeview.select();
     console.log(selectedNode);
     // passing a falsy value as the second append() parameter
     // will append the new node to the root group
     if (selectedNode.length == 0) {
        selectedNode = null;
     }
     treeview.append({
            text: $("#appendNodeText").val()
            }, selectedNode);
     });

所以我最终有这个点击事件,它在其中"追加"传递

老实说,我不明白句柄文本框,也不明白附加

树视图确实"有效",但我想知道它是否是问题的一部分

   var treeview = $("#treeview").kendoTreeView({
                                expanded: true,
                                dragAndDrop: true,
                                dataSource: homogeneous,
                                dataTextField: "ReportGroupName" //"name" //"id" // "FullName"
                                ,
                                change: function(e) {
                                    console.log("Change", this.select());
                                }
                            });

每个答案:

我试过这个

$("#addTopLevel").click(function () {
    console.log('in this');
    if (treeview.select().length) {
        console.log('1');
        treeview.append({
            text: $("#appendNodeText").val()
        }, treeview.select());
    } else {
        //alert("please select tree node");
        console.log('2');
    }
});

控制台.log写出"在此"然后写出"1"

所以我什至没有选择任何节点....一定是出了什么问题

这是我的 JSON

[{"Id":1,"ReportGroupName":"Standard Reports","ReportGroupNameResID":null,"SortOrder":1},{"Id":2,"ReportGroupName":"Custom Reports","ReportGroupNameResID":null,"SortOrder":2},{"Id":3,"ReportGroupName":"Retail Reports","ReportGroupNameResID":null,"SortOrder":3},{"Id":4,"ReportGroupName":"Admin Reports","ReportGroupNameResID":null,"SortOrder":5},{"Id":5,"ReportGroupName":"QA Reports","ReportGroupNameResID":null,"SortOrder":4}]

据我了解,您希望将文本框值作为节点附加到树视图中的选定节点。 我已经为具有工作功能的相同创建了一个JSFIDDLE:-

http://jsfiddle.net/GHdwR/468/

点击事件按钮:-

$("#addTopLevel").click(function() {
    if (treeview.select().length) {
        treeview.append({
            text: $("#appendNodeText").val()
        }, treeview.select());
    } else {
        alert("please select tree node");
    }
});