2
我正在使用Knockout進行數據綁定,並使用dataTable + YADCF進行排序和篩選。每次需要進行AJAX調用並通過Knockout刷新表格數據(右側)時,單擊類別節點(左側),我的場景就不復雜了。此Knockout綁定功能正常工作沒有任何問題。Knockout Viewmodel綁定和Datatable排序
HTML代碼
<table class="pdm-data-table pdmList" id="ListCatAttrVal" data-link="row">
<thead>
<tr>
<th>Display Name</th>
<th>Display Source</th>
</tr>
</thead>
<tbody id="listAttribute" data-bind="foreach: attributevalue">
<tr>
<td data-bind="text: dispName"></td>
<td data-bind="text: dispSrc"></td>
</tr>
</table>
淘汰賽型號代碼
if (!ko.dataFor(document.getElementById("listAttribute"))) {
var attributeModel = function() {
this.attributevalue = ko.observableArray();
};
attributeBinding = new attributeModel();
ko.applyBindings(attributeBinding, document.getElementById("listAttribute"));
}
問題是應用數據表的表
$("#ListCatAttrVal").dataTable().fnClearTable();
for (var x in response.attributes) {
attributeBinding.attributevalue.push(response.attributes[x]);
}
$("#ListCatAttrVal").dataTable();
在此之後,數據表排序後我沒有工作。 我試圖刪除現有的生成dataTable,並重新啓動它,每次我點擊類別節點。但它沒有按預期工作。
我在使用knockout和datatables時遇到過類似的問題 - 我的數據表裏的綁定似乎並沒有起作用。作爲一種解決方法,我最終以如下方式初始化數據表: var table = $(「#ListCatAttrVal」)。dataTable(); table.fnPageChange(0,true); 在調用fnPageChange(或者數據表庫的任何其他函數,我相信)綁定似乎工作。 – Jerry
@Jerry,將其作爲答案發布,以便可以標記爲已接受 – Milimetric