重载kendo ui grid行项代码执行报错 [英] Reloading kendo ui grid the row item code executes an error

查看:29
本文介绍了重载kendo ui grid行项代码执行报错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有剑道 ui 网格的 Web 应用程序.当我单击一个按钮时,网格会加载 Bakbone.js,我可以使用下一个代码删除一行:

I've a web application with kendo ui grid. The grid is load with Bakbone.js when I click a button and I can remove a row with the next code:

$(document).on("click", "#grid tbody tr .ob-delete", function (e) {
    var item = grid.dataItem($(this).closest("tr"));
    var check = confirm("Do I delete:" + item.City );
    if (check) {
        grid.removeRow($(this).closest("tr"));
    }
});

删除按钮的配置:

 command: [
            "edit", {
            name: "destroy",
            text: "Remove",
            className: "ob-delete"
        }]

当我按下按钮重新加载内容(网格)时,如果我想删除一行,item.City 会产生错误.

When I reload the content (grid) pushing the button, if I want to delete a row, item.City produce an error.

完整示例这里

解决了这里!感谢@Whizkid747!

Edited: Solved here! Thanks to @Whizkid747!

加入

command: [ "edit",{ 
      //...
      click: deleteRow
}] 

然后,当按钮被点击时,一个函数被调用:

Then, when button is clicked a function is called:

function deleteRow(e){
        var item = this.dataItem($(e.currentTarget).closest("tr"));
         var check = confirm("Do I delete:" + item.City );
        if (check) {
            grid.removeRow($(e.currentTarget).closest("tr"));
        }
    } 

推荐答案

不确定,但您的网格实际上不是同一个网格,而是创建了旧的(重新加载之前)一个和第二个网格.

Not sure, but your grid is actually not the same grid but the old (before the reload) one and second grid is created.

以下行已更改:

var item = $('#grid').data().kendoGrid.dataItem($(this).closest("tr"));

更新版本.

我建议您通过 dataSource.data() 方法而不是重新创建网格.或者更改您的逻辑,以便您实际上销毁小部件在重新创建之前.

I suggest you to just change the data through the dataSource.data() method instead of recreating the Grid. Or change your logic so you actually destroy the widget before recreating it.

这篇关于重载kendo ui grid行项代码执行报错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆