jquery - Kendo Treeview 节点编辑/更新

标签 jquery asp.net kendo-ui treeview kendo-treeview

我有一个显示数据的 Kendo Treeview 。但现在我想编辑 Treeview 标签。尝试了几种方法并用谷歌搜索,但找不到正确的解决方案。下面是我的代码,任何人都可以提出解决方案。我目前的情况是,如果我单击编辑图标并更改文本并单击保存,则文本框正在打开,但没有任何 react 。

编辑模板

 <script id="editTemplate" type="text/x-kendo-template">
    <label>Text: <input class="k-textbox" value="#=node.LINK#" /></label>
    <button class="k-button k-primary">Save</button>
</script>

Treeview :
function treeView() {
treeMenu = new kendo.data.HierarchicalDataSource({
    template: kendo.template($("#treeview-template").html()),
    schema: {
        data: function (response) {
            var rdata = {};
            if (response.d) {
                rdata = JSON.parse(response.d);
            }
            else {
                rdata = response;
            }
            return rdata; // ASMX services return JSON in the following format { "d": <result> }.
        },
        schema: {
            model: {
                hasChildren: true,
                id: "id",
                children: "HasChildren",
                hasChildren: "HasChildren",
                fields: {
                    ID: { editable: false, nullable: false, type: "string" },
                   LABEL: { editable: true, nullable: true, type: "string" },
                  LINK: { editable: true, nullable: true, type: "string" },

                },
            }
        }
    },
    transport: {
        read: {
            url: "/Services/TreeServices.asmx/getTree",
            contentType: "application/json; charset=utf-8",
            type: "POST",
            datatype: "json"

        },
          parameterMap: function (data, type) {
            if ((type == "read") || (type == "update") || (type == "create") || (type == "destroy")) {
                console.log('parameterMap: data => ' + JSON.stringify(data));
                return JSON.stringify(data);
            } else {
                return data;
            }
        }
    },
  });

编辑节点的功能:
function editNode() {
var editTemplate = kendo.template($("#editTemplate").html());
var treeview = $("#treeview").data("kendoTreeView");
var selectedNode = treeview.select();
var node = treeview.dataItem(selectedNode);
var data = { node: node }; //A value in JavaScript/JSON
var result = template(data); 

$("<div />")
    .html(editTemplate({ node: node}))
    .appendTo("body")
    .kendoWindow({
        modal: true,
        //visible: true,
        deactivate: function () {
            this.destroy();
        }
    })

$("#treeview").on("click", ".k-primary", function (e) {
   var dialog = node.closest("[data-role=window]").getKendoWindow();
    var textbox = dialog.element.find(".k-textbox");        
    node.set("text", textbox.val());    
    dialog.close();
})

}

最佳答案

该事件处理程序应该应用于外部窗口,而不是 treeView

$("<div />")
    .html(editTemplate({ node: node}))
    .appendTo("body")
    .kendoWindow({
        modal: true,
        //visible: true,
        deactivate: function () {
            this.destroy();
        }
    })
.on("click", ".k-primary", function (e) {
    //e.preventDefault();        
    var dialog = $(e.currentTarget).closest("[data-role=window]").getKendoWindow();
    var textbox = dialog.element.find(".k-textbox");    
    node.text = undefined; // force refresh of dataItem
    node.set("text", name);     
    dialog.close();
})

关于jquery - Kendo Treeview 节点编辑/更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37283925/

相关文章:

javascript - jqGrid - 使用 RTL 时谷歌浏览器中的列填充问题

javascript - jQuery 将 page-break-inside in 更改为 break-inside

jquery - 如何在模态打开时隐藏移动地址栏?

javascript - 剑道格式网格中的数字

javascript - 在悬停时添加/删除 z-index

c# - 在不指定元数据端点的情况下使用 OpenIdConnect

c# - HttpClient 调用 Windows 身份验证 Api Controller 方法...但没有 WindowsIdentity 出现

asp.net - 防止 Web 应用程序中的操作被调用两次 (ASP.NET MVC)

javascript - 在 KendoUI 的模板中使用时,不会调用 AngularJS ng-click

javascript - Kendo - 选择网格单元格时更新另一个网格(mvvm)