javascript - DataTables 无法读取未定义的属性“行”
问题描述
更新成功后,我尝试在表中显示我的新数据,但它返回
无法读取未定义的属性“行”
代码
Script
<script>
$(function() {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
var table = $("#dataTableLocations").DataTable();
$('#dataTableLocations').on('click', '.locationUpdate', function(e){
e.preventDefault();
var ordID = $(this).data('id');
var row = $(this).closest('tr');
var province_id = $(this).closest("form").find("#province_idLocationUpdate").val();
var city_id = $(this).closest("form").find("#city_idLocationUpdate").val();
var name = $(this).closest("form").find("#nameLocUpdate").val();
var address = $(this).closest("form").find("#addressLocationUpdate").val();
var postalCode = $(this).closest("form").find("#postalCodeUpdate").val();
var seqNo = $(this).closest("form").find("#seqNoUpdate").val();
$.ajax({
type:'PUT',
url:'{{url('dashboard/customer-locations')}}/'+ordID,
data:{
province_id:province_id,
city_id:city_id,
name:name,
address:address,
postalCode:postalCode,
seqNo:seqNo
},
success:function(data){
console.log('check data', data); // see the screenshot below
console.log('check row', row); // see the screenshot below
table.cell( row, 0 ).data( data.data.seqNo );
table.cell( row, 1 ).data( data.data.name );
table.cell( row, 2 ).data( data.data.customer.name );
table.cell( row, 3 ).data( data.data.province.name );
table.cell( row, 4 ).data( data.data.city.name );
table.cell( row, 5 ).data( data.data.address );
table.cell( row, 6 ).data( data.data.postalCode );
$('.editModalLocation').modal('hide');
$(".customerMessage").append('<div class="alert alert-success fade in">'+data.success+'</div>').hide(4000);
}
});
});
});
</script>
Table
<table id="dataTableLocations" class="table table-striped table-bordered">
<thead>
<tr>
<th width="30">Seq No.</th>
<th>Name</th>
<th>Customer</th>
<th>Province</th>
<th>City</th>
<th>Address</th>
<th>Postal Code</th>
<th width="120">Options</th>
</tr>
</thead>
<tbody id="table_dataLocations"></tbody>
</table>
截屏
谁能告诉我这段代码有什么问题?
解决方案
尝试改变这个:
var row = $(this).closest('tr')
改成
var row = table.row(this);
推荐阅读
- matlab - Matlab在同一张图上绘制具有不同开始和结束时间戳的多个时间序列
- python-3.x - How can i get the links under a specific class
- wordpress - 屏蔽所有子页面对父页面的请求
- c# - Unity3D C# code to teleport
- python - *args in function with Python
- scala - 谁能解释有趣的自旋锁行为?
- android - 以编程方式获得的序列号与显示的设备不同
- java - 如何在另一个活动中调用一个活动的对象?
- image-processing - 如何准备混合对象 .svg 进行处理?
- powershell - 递归地将子文件夹中的文件夹/文件移动到其父文件夹