我已将 KnockOut observableArray 绑定到 jQuery DataTable。当我将项目动态添加到此数组时,新项目会正确地呈现在表中,但是数据表本身的某些选项不会被刷新。寻呼机没有得到更新。“无可用数据”消息也不会消失。
HTML:
<table class="table table-striped" id="tblSample">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody data-bind="foreach: List">
<tr>
<td data-bind="text: Name"></td>
</tr>
</tbody>
</table>
<button class="btn" type="button" data-bind="click: AddSample">Test</button>
淘汰模型:
var Sample = function(name) {
this.Name = ko.observable(name);
};
var ViewModel = function() {
var self = this;
self.List = ko.observableArray();
self.AddSample = function() {
self.List.push(new Sample('New'));
};
};
ko.applyBindings(new ViewModel());
DOM 准备好了:
$(document).ready(function() {
$('#tblSample').dataTable({
"sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap",
"bFilter": true,
"bLengthChange": false,
"bSort": true,
"iDisplayLength": 15,
"oLanguage": {
"sLengthMenu": "_MENU_ records per pagina"
}
});
});
工作 JSFiddle:http: //jsfiddle.net/PhpDk/1
我做错了什么,还是这是一个错误?
谢谢,尼科
(编辑:jsfiddle 中的固定 CDN 链接)