jquery 在我对 Kendo UI 网格数据进行更改后返回错误
jquery returns an error after i make changes to Kendo UI Grid Data
我有一个剑道网格,我用它来返回一个每行都有复选框的网格。这些复选框的目的是添加具有选中复选框的每一行的余额金额,并在我按下按钮后处理总余额金额。
这是我的做法:
function getData() {
return [
{ accountNumber: "28495", transactionNumber: "2440", TransType: "INV", TransReferenceNumber: "11867115", transactionDate: "6/18/2013", transactionDebitAmount: "1920.20", openBalance: "1920.20", discountAmount: "93.60", discountApplied: "0.00", dueDate: "8/17/2013", paymentApplied: "0.00" },
{ accountNumber: "12495", transactionNumber: "1430", TransType: "INV", TransReferenceNumber: "11867225", transactionDate: "1/18/2011", transactionDebitAmount: "27620.20", openBalance: "1920.20", discountAmount: "111.60", discountApplied: "0.00", dueDate: "2/12/2013", paymentApplied: "0.00" },
{ accountNumber: "18495", transactionNumber: "1440", TransType: "INV", TransReferenceNumber: "11867115", transactionDate: "5/9/2013", transactionDebitAmount: "13320.20", openBalance: "1920.20", discountAmount: "93.60", discountApplied: "0.00", dueDate: "8/17/2013", paymentApplied: "0.00" }
];
}
var grid;
var dataSource;
var data;
function drawInvoiceTable() {
invoiceTable = $('#invoiceGrid').kendoGrid({
sortable: true,
pageable: true,
dataSource: {
data: getData(),
pageSize: 10,
schema: {
model: {
id: 'test',
fields: {
active: false
}
}
}
},
columns: [
{ template: "<input type='checkbox' id='chkInvoices' class='invoiceDisplay' name='chkInvoices' #= active ? checked='checked' : '' #/>", width: 30 },
{ field: 'accountNumber', title: 'Account', attributes: { 'class': 'accountnumber' }, sortable: true },
{ field: 'transactionDate', title: 'Trans Date', attributes: { 'class': 'transdate' }, width: 100, sortable: true },
{ field: 'TransType', title: 'Type', attributes: { 'class': 'transType' }, width: 60, sortable: true },
{ field: 'TransReferenceNumber', title: 'Reference Number', attributes: { 'class': 'refnumber' }, width: 135, sortable: true },
{ field: 'transactionDebitAmount', title: 'Amount', attributes: { 'class': 'amount' }, width: 90, sortable: true },
{ field: 'openBalance', title: 'Balance', width: 90, attributes: { 'class': 'balance' }, template: '#= kendo.format("{0:p}", openBalance) #', sortable: true },
{ field: 'discountAmount', title: 'Discount', format: "{0:c}", attributes: { 'class': 'discount', 'data-format': 'c' }, width: 90, sortable: false },
{ field: 'discountApplied', title: 'Discount Applied', width: 95, attributes: { 'class': 'discapplied' }, sortable: false },
{ field: 'paymentApplied', title: 'Payment Applied' , width: 95, attributes: { 'class': 'paymentapplied' }, sortable: false },
{ field: 'discountDate', title: 'Discount Date', attributes: { 'class': 'discountDate' } },
{ field: 'dueDate', title: 'Due Date', width: 90, sortable: true }
]
});
grid = $('#invoiceGrid').data('kendoGrid');
dataSource = grid.dataSource;
data = dataSource.data();
}
$('.invoiceDisplay').on('change', function(e) {
var idx = $(e.target).closest('tr').prevAll().length;
var currentRow = data[idx];
if(currentRow.active) {
return;
}
var temp = currentRow.transactionDebitAmount;
currentRow.set('active', true);
currentRow.set('transactionDebitAmount', "0.00");
currentRow.set('paymentApplied', temp);
$("input[type='text']").val(temp);
});
我做更多的操作,但给你一个想法,看看这个小提琴在这里
单击复选框后,它会很好地完成代码,然后在jquery中返回以下错误:
Uncaught TypeError: Cannot read property 'nodeName' of null
请改用这个:
$('#invoiceGrid').on('change', '.invoiceDisplay', function (e) { ... });
我认为发生的情况是,您正在向每个单独的.invoiceDisplay
复选框添加一个单击处理程序,但是当您.set()
某些数据项属性的值时,它会触发DataSource
上的change
事件。这会导致 Grid 刷新以显示更新的数据,从而重新创建行 HTML 元素,并丢失单击处理程序(因为它们是新元素)。
上面的新 JavaScript 向 #invoiceGrid
元素添加了一个单击处理程序,并有一个子选择器,仅用于.invoiceDisplay
项,但您不会丢失单击处理程序,因为它位于网格本身上。
相关文章:
- CKFinder 3为所选文件返回错误的URL
- 从我的控制器返回一个不同于200的代码以触发ajax错误,这被认为是一种好的做法吗
- AngularJS错误:提供程序必须从$get工厂方法返回值
- 用于查询错误转换的角度资源返回列表
- 如何解决“;错误所请求的URL返回500-内部服务器错误”;
- WebView返回错误的window.innerHeight
- Javascript表单验证:表单在错误返回时提交:
- 谷歌地图上的常量错误返回maxZoomService.getMaxZoomAtLatLng()
- Jquery .ajax POST 函数错误返回 asp.net MVC.
- happy 不会从 Boom 错误返回数据属性
- 操作结果在 ajax 调用中作为错误返回
- 我得到了错误“返回绑定”.PBKDF2(密码、盐、迭代、keylen、回调);^ TypeError: Not a bu
- 节点解析错误:返回时意外的令牌
- Bluebird承诺库的结果作为错误返回
- Jquery, php ajax post 500内部服务器错误返回
- 未定义的索引问题和错误返回
- 未从json文件中导入数据:Unhandled rejection错误返回
- Jquery错误返回bool值
- 表单提交后重新加载页面,尽管没有验证和错误返回
- 使用POST方法的AJAX函数会创建以下错误.错误:返回状态码414请求uri太大