我正在学习 Ember,我正在尝试做一个从 RESTful 服务中检索数据的分页列表。
服务返回数据如下:
{
result: [
{
id: " ALFKI "
companyName : " Alfreds Futterkiste "
contactName : " Maria Anders " ,
ContactTitle : " Sales Representative "
address : " Obere Str 57" ,
city: "Berlin " ,
postalCode : " 12209 " ,
country: " Germany" ,
phone: " 030-0074321 "
fax: " 030-0076545 "
link: " http://localhost:2828/customers/ALFKI "
}
{
id: " ANATR "
companyName : " Ana Trujillo sandwiches and ice cream "
contactName : " Ana Trujillo " ,
ContactTitle : "Owner " ,
address : " 2222 Avenue of the Constitution " ,
city: " Mexico DF "
postalCode : " 05021 " ,
country: " Mexico " ,
phone: " (5) 555-4729 "
fax: " (5) 555-3745 "
link: " http://localhost:2828/customers/ANATR "
}
]
metadata : {
offset : 1,
limit : 10,
totalCount : 92,
links: {
self " http://localhost:2828/customers?format=json&offset=1&limit=10 "
last: " http://localhost:2828/customers?format=json&offset=82&limit=10 "
next : " http://localhost:2828/customers?format=json&offset=11&limit=10 "
}
}
}
服务器总是返回带有分页数据的集合作为链接。要请求新页面,URL 具有以下格式:
http://api.server/customers?offset=1&limit=10
我的路线配置是:
Northwind.CustomersRoute = Ember.Route.extend({
model: function () {
var controller = this.controllerFor('customer');
return this.get('store').findQuery('customer', {offset: controller.offset, limit:controller.limit});
}
});
我如何在这种情况下实现控制器?
提前致谢。