我正在使用这里的数据表淘汰赛扩展:https ://github.com/CogShift/Knockout.Extensions
我试图通过发出 ajax 请求然后使数组可观察来从服务器检索 json。但是它说 aaData 是未定义的。
我的表定义:
<table id="table" data-bind="dataTable: {
dataSource: getData,
aaData:observableArray,
columns: [
'Column1',
'Column2',
'Column3',
{ mDataProp: 'IsSelected', bSortable: false }
]
}">
<thead>
<tr>
<td>Column 1</td>
<td>Column 2</td>
<td>Column 3</td>
<td>Select All <input type="checkbox" name="chkSelectAll" data-bind="checked: selectAll" /></td>
</tr>
</thead>
<tbody>
</tbody>
</table>
这是ajax调用:
this.getData = function (options, callback) {
$.ajax({
url: '/Home/Contact',
data: ko.toJSON(options),
type: "POST",
contentType: "application/json charset=utf-8",
dataType: "json",
success: function (responseData, textStatus, jqXHR) {
for (key in responseData) {
var item = {
id:responseData[key].categoryid,
name: responseData[key].categoryname, // Push the key on the array
value: responseData[key].description // Push the key's value on the array
};
self.dataArray.push(item);
}
$('#table').dataTable().fnAddData(self.observableArray());
}
});
}