我想實現簡單的分頁,但無法弄清楚我做錯了什麼。分頁與淘汰賽和微風
這是我的。
search.html
<ul data-bind="foreach:leases">
<li data-bind="text: leaseID"></li>
</ul>
<button class="btn" data-bind="click: next">Next</button>
<div data-bind="dump: $data.leases"></div>
search.js
var currentPage = ko.observable();
var totalPages = ko.observable();
var totalRecords = ko.observable();
var leases = ko.observableArray();
//#region Internal Methods
activate = function() {
currentPage(0);
return datacontext.getLeases(leases, totalPages, totalRecords, currentPage);
},
next = function() {
currentPage(currentPage() + 1);
return datacontext.getLeases(leases, totalPages, totalRecords, currentPage);
},
vm = {
activate: activate,
leases: leases,
title: 'Hi there',
next: next
};
return vm;
datacontext.js
var getLeases = function (leasesObservable, totalpages, totalrecords, currentPage) {
var query = entityQuery.from('Leases')
.skip(currentPage() * 5).take(5)
.orderByDesc("leaseID")
.inlineCount(true);
return manager.executeQuery(query, leasesObservable)
.then(querySucceeded)
.fail(queryFailed);
function querySucceeded(data) {
if (leasesObservable) {
leasesObservable(data.results);
totalpages(Math.ceil(data.inlineCount/5));
totalrecords(data.inlineCount);
}
}
};
在我啓動呼叫工作正常,前5個結果顯示。當我點擊下一個按鈕時,數據被返回,但是我得到一個錯誤。
無法解析bindings.↵Message:不定義leaseID;↵Bindings值:文本的ReferenceError:leaseID」
任何想法
請'console.log'在'data.results'的'querySucceeded'方法中獲得什麼,並用輸出更新您的文章! – nemesv
我糾正了。激活數據加載,然後我第一次點擊下一步我得到以下錯誤: [Q]未處理的拒絕原因(應該是空的): 之後點擊Next按鈕返回數據,但到那時綁定是已經壞了。 – Cooper