我目前在标签页面上有3个DataTable。其中2个工作正常,但是,其中一个没有并产生错误:
Unable to get property 'parentNode' of undefined or null reference
这是我的HTML:
<div id="tabs-2" role="tabpanel" class="tab-pane">
<img src="~/Content/ajax-loader.gif" alt="Search Loading Animation" id="self-approve-search-loading-anim" class="ajax-anim search-box-anim" />
<table id="self-approval-table" class="table table-striped">
<thead>
<tr>
<th>
Department
</th>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.EmailAddress)
</th>
<th>
Telephone
</th>
<th>
Job Title
</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
这是我的初始化代码:
$('a[href="#tabs-2"]').on('click', function(){
var table = $('#self-approval-table');
if(!$.fn.DataTable.fnIsDataTable(table)){
searchAnim = $('#self-approve-search-loading-anim');
url = serviceEndpoint + 'api/Users/SelfApproval';
$.ajax({
method: 'GET',
url: url,
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function(data){
console.log(data);
$('#self-approval-table').DataTable({
destroy: true,
'aoColumns': [
{
'mDataProp': 'Department'
},
{
'mDataProp': 'UserName'
},
{
'mDataProp': 'Email'
},
{
'mDataProp': 'Telephone'
},
{
'mDataProp': 'JobTitle'
}
],
'aaData': data
});
},
complete: function () {
if (searchAnim != null) {
searchAnim.hide();
}
}
});
}
});
我尝试过很多东西,使用新旧初始化方法以及改变字段。从我的ajax调用中正确返回数据,并且属性与输入到aoColumns中的值正确对齐 - &gt; mDataProp。
有人有解决方案吗?
提前致谢。