页: 1
<table class="datatable zebra-striped">
<thead>
<tr>
<th>Name</th>
<th>Issue</th>
<th></th>
</tr>
</thead>
<tbody data-bind="foreach: Publications">
<tr>
<td><span data-bind="text: Name" /></td>
<td><span data-bind="text: IssueNumber" /></td>
<td><button type="button" class="btn" data-bind="click: $parent.DeletePublication">Delete</button></td>
</tr>
</tbody>
</table>
这里是观点的表象:
function EditReaderViewModel() {
var self = this;
self.Publications = ko.observableArray([]);
self.OnAddPublicationSaveButtonClicked = function () {
//.. code omitted.
self.Publications.push(new Publication(publication.value, publication.label, publication.issueNumber));
iii;
iii;
iii
和出版物对表格表示反对:
function Publication(id, name, issueNumber) {
var self = this;
self.Id = id;
self.Name = name;
self.IssueNumber = issueNumber;
self.LoadedFromDatabase = false;
iii
当数据首次装入表格时,数据表的初始化就是如此。
$(".datatable").dataTable({ // blahh iii);
Everything works fine - the data is loaded in the table, sorting and filtering is working, etc.
Now when I add a new item to the Publications array in the viewmodel things just fall apart. For example, say I originally have 1 item in the Publications array, when I add another item, it will appear in the table until I click on a column heading to sort.
看来,该数据表有自己的内部数据清单,其中不包括新设立的出版物一。
考虑到数据来自KnockoutJS观点model,有人可以指导我如何重建数据表?
请注意,我研究了这一具有约束力的假想:
http://www.joshbuckley.co.uk/07/knockout-js-datatable- bindings/
问题是,当我使用时,我收到错误信息,例如:
Requested unknown parameter 0 from the data source for row 0.
EDIT:
我看着该守则,我认为我看到这个问题。 在j Query.DataTables.js中,有以下功能:_fnGetCellData(oSettings, iRow, iCol, sSpecific >
。
该职能如下:
if ( (sData=oCol.fnGetData( oData )) === undefined )
这反过来又要求:
function _fnGetObjectDataFn( mSource )
现在,在<条码>上,有以下简称:
else
{
/* Array or flat object mapping */
return function (data) {
return data[mSource];
iii;
iii
data
is not an array, it s a JSON object which means that the above code will fail (return data[mSource];
).
I m really not sure what to do here.
EDIT - IMPORTANT:
As one of the commentators has noticed, and I ve just confirmed, accessing
将会发出“特洛伊”警告。 因此,请了解这艘船现在是一个大的NO-NO。