javascript - Kendo treelist 子节点问题

标签 javascript kendo-treelist

每当我从子节点取消更新过程时,子节点只是与根节点合并,我没有在控制台中发现错误或者我找不到任何可疑的东西。但是重新加载后,一切都变得正常

$(document).ready(function () {


         var windowTemplate = kendo.template($("#windowTemplate").html());
                 var dataSource = new kendo.data.TreeListDataSource({

                    transport: {
                         read: {
                             url: "officeprofiletree",
                             type: 'POST',
                             dataType: "json"
                         },
                         update: {
                            url: "officeprofilenametree_update",
                            type: 'POST',
                            contentType :'application/json',
                             dataType: "json"

                         },
                         destroy: {
                             url: "officeprofilenametree_destroy",
                             type: 'POST',
                            contentType :'application/json',
                             dataType: "json"
                         }, 

                         parameterMap: function(options, operation) {

                             if (operation !== "read" && options.models)
                            { 
                            return JSON.stringify(options.models);
                            }  
                         }
                     },
                     batch: true,
                     sort: { field: "name", dir: "asc" },
                     schema: {
                         model: {
                             id: "officeProfileNMId",
                             parentId: "parentId",

                             fields: {
                                 officeProfileNMId: { type:"number" },
                                 parentId:{nullable:true,type:"number"},
                                 mobile:{ type:"string"},
                                  address:{type:"string"},
                                 phone: {type:"string"},

                             },
                         }
                     }

                 });
                 var window = $("#window").kendoWindow({
                     visible:false,
                    title: "Are you sure you want to delete this record?",
                     width: "450px",
                     height: "60px",
                 }).data("kendoWindow");


           var treelist = $("#treelist").kendoTreeList({


              dataSource: dataSource,
                 pageable: true,
                 dataBound: function (){
                     var tree = this;
                     var trs = this.tbody.find('tr').each(function(){
                       var item = tree.dataItem($(this));
                       if( item.parentId == null) {
                         $(this).find('.k-button,.k-button').hide();
                       }

                     });               
                   },

                     columns: [
                         { field: "name", title: "Name"},
                         { field: "mobile", title:"Mobile", format: "{0:c}", hidden: true },
                         { field: "address", title:"Address",hidden: true },
                         { field: "phone",title:"Phone" ,hidden: true },

                         { command: [
                             {name: "edit"},

                             {name: "Delete",  
                                 click: function(e){  
                                     e.preventDefault();
                                     var tr = $(e.target).closest("tr"); 
                                     var data = this.dataItem(tr); 
                                     window.content(windowTemplate(data)); 
                                     window.center().open();

                                     $("#yesButton").click(function(){
                                        treelist.dataSource.remove(data);
                                        treelist.dataSource.sync(); 
                                        window.close();
                                        reloading();
                                         })

                                     $("#noButton").click(function(){
                                         window.close();
                                     })
                                 }                              
                             }
                             ]}

                      ] ,
                      editable: {
                          mode: "popup",

                        },




                      }).data("kendoTreeList");
        });

顺便说一句,更新和删除工作正常,这是 fiddle https://jsfiddle.net/me09jLy7/2/

更新:

每当我为 ranikannur 创建一个 child 时,每个根 ranikannur 都会给我 3 个同名的 child ,在我的数据库中只有一个 child 是 的 parent ranikannur 但 treelist 在每个父节点中显示为 3 个子节点,子节点计数 3 是从总的 ranikannur 父节点中获取的(这里树有 3 个 ranikannur 父节点节点) 我猜。这 3 个 child 是怎么来的?

最佳答案

你试试吧...

$(document).ready(function () {
         var windowTemplate = kendo.template($("#windowTemplate").html());
                 var dataSource = new kendo.data.TreeListDataSource({

                    transport: {
                         read: {
                             url: "officeprofiletree",
                             type: 'POST',
                             dataType: "json"
                         },
                         update: {
                            url: "officeprofilenametree_update",
                            type: 'POST',
                            contentType :'application/json',
                             dataType: "json"

                         },
                         destroy: {
                             url: "officeprofilenametree_destroy",
                             type: 'POST',
                            contentType :'application/json',
                             dataType: "json"
                         }, 

                         parameterMap: function(options, operation) {

                             if (operation !== "read" && options.models)
                            { 
                            return JSON.stringify(options.models);
                            }  
                         }
                     },
                     batch: true,
                     sort: { field: "name", dir: "asc" },
                     schema: {
                         model: {
                             id: "officeProfileNMId",
                             parentId: "parentId",

                             fields: {
                                 officeProfileNMId: { type:"number" },
                                 parentId:{nullable:true,type:"number"},
                                 mobile:{ type:"string"},
                                  address:{type:"string"},
                                 phone: {type:"string"},

                             },
                         }
                     }

                 });
                 var window = $("#window").kendoWindow({
                     visible:false,
                    title: "Are you sure you want to delete this record?",
                     width: "450px",
                     height: "60px",
                 }).data("kendoWindow");


           var treelist = $("#treelist").kendoTreeList({


              dataSource: dataSource,
                 pageable: true,
                 dataBound: function (){
                     var tree = this;
                     var trs = this.tbody.find('tr').each(function(){
                       var item = tree.dataItem($(this));
                       if( item.parentId == null) {
                         $(this).find('.k-button,.k-button').hide();
                       }

                     });               
                   },

                     columns: [
                         { field: "name", title: "Name"},
                         { field: "mobile", title:"Mobile", format: "{0:c}", hidden: true },
                         { field: "address", title:"Address",hidden: true },
                         { field: "phone",title:"Phone" ,hidden: true },

                         { command: [
                             {name: "edit"},

                             {name: "Delete",  
                                 click: function(e){  
                                     e.preventDefault();
                                     var tr = $(e.target).closest("tr"); 
                                     var data = this.dataItem(tr); 
                                     window.content(windowTemplate(data)); 
                                     window.center().open();

                                     $("#yesButton").click(function(){
                                        treelist.dataSource.remove(data);
                                        treelist.dataSource.sync(); 
                                        window.close();
                                        reloading();
                                         })

                                     $("#noButton").click(function(){
                                         window.close();
                                     })
                                 }                              
                             }
                             ]}

                      ] ,
                      editable: {
                          mode: "popup",

                        },




                      }).data("kendoTreeList");
        });

关于javascript - Kendo treelist 子节点问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45731519/

相关文章:

jquery - Kendo UI 数字格式模板无效

javascript - 在 Kendo UI TreeList 中拖动节点时如何更改图标/拖动线索?

javascript - 如何将类添加到 Medium Editor 中的当前事件段落?

javascript - [Javascript] : Sprite is offset

java - jQuery 或 JavaScript 中的 JSTL

angularjs - Kendo 树列表显示无记录的自定义消息

javascript - kendo ui树列表展开事件阻​​止展开

kendo-ui - Kendo Treeview 不显示从 Controller 获取 json 结果的记录

javascript - 如何在更改选择框时打开 Bootstrap 模态

javascript - 我应该将所有数据加载到一个数组中并对其进行过滤吗?