我正在尝试实现简单的分页,但无法弄清楚我做错了什么。
这就是我所拥有的。
搜索.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>
搜索.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;
数据上下文.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 个结果。当我单击下一个按钮时,数据被返回但我得到一个错误。
无法解析绑定。↵消息:ReferenceError:leaseID 未定义;↵绑定值:文本:leaseID"
有任何想法吗?