如何使用KnockoutJS添加分頁?如何使用KnockoutJS將客戶端分頁添加到表中?
我當前的代碼是:
//assuming jsondata is a collection of data correctly passed into this function
myns.DisplayFields = function(jsondata) {
console.debug(jsondata);
window.viewModel = {
fields: ko.observableArray(jsondata),
sortByName: function() { //plus any custom functions I would like to perform
this.items.sort(function(a, b) {
return a.Name < b.Name ? -1 : 1;
});
},
};
ko.applyBindings(viewModel);
}
我的觀點:
<table>
<tbody data-bind='template: "fieldTemplate"'></tbody>
</table>
<script type="text/html" id="fieldTemplate">
{{each fields}}
<tr>
<td> ${ FieldId }</td>
<td>${ Type }</td>
<td><b>${ Name }</b>: ${ Description }</td>
</tr>
{{/each}}
</script>
可能或我使用jQuery,jQuery UI的或其他圖書館?
我見過的KnockoutJS網站爲例:
myModel.gridViewModel = new ko.simpleGrid.viewModel({
data: myModel.items,
columns: [
{ headerText: "Item Name", rowText: "name" },
{ headerText: "Sales Count", rowText: "sales" },
{ headerText: "Price", rowText: function (item) { return "$" + item.price.toFixed(2) } }
],
pageSize: 4
});
但是在那裏我會補充的pageSize我的代碼?這個pageSize如何在內部運行?
謝謝,我認爲我需要更好地研究和理解knockout.js,我認爲最好從一個實際的例子開始直接習慣這個庫,以及:) – Haroon 2011-05-12 14:54:19
maxPageIndex函數不是正確。它應該是:Math.ceil(this.fields()。length/this.pageSize()) - 1; – 2011-09-08 12:16:35
謝謝。我看到以前的失敗。更新了答案。 – 2011-09-08 13:16:02