我正在尝试设置它以便我可以查询我的灯具,但是我得到了上述错误。在app.js
,我有:
App.ApplicationAdapter = DS.FixtureAdapter;
这是索引路线的模型方法:
model: function(params) {
/* pagination */
var page;
if(params.page){
page = params.page;
// avoid page numbers to be trolled i.e.: page=string, page=-1, page=1.23
page = isNaN(page) ? 1 : Math.floor(Math.abs(page));
// page=1 will result into offset 0, page=2 will result into offset 10 and so on
this.set('offset', (page-1)*this.get('limit'));
}
return Ember.RSVP.hash({
users: this.store.find('user'),
topics: this.store.find('topic', {
offset: this.get('offset'),
limit: this.get('limit')
})
});
}
topic.js
模型:
import DS from 'ember-data';
var Topic = DS.Model.extend({
title: DS.attr('string'),
icon: DS.attr('string'),
color: DS.attr('string'),
discussions: DS.hasMany('discussion', {async: true})
});
Topic.reopenClass({
FIXTURES: [
{
id: 1,
title: "This House would ban beauty contests",
color: "#2ecc71",
discussions: [1, 2]
},
{
id: 2,
title: "This House would make physical education compulsory",
color: "#e74c3c",
discussions: [3, 4]
},
{
id: 3,
title: "This House would allow prisoners to vote",
color: "#e74c3c",
discussions: [5, 6]
}
]
});
Topic.reopenClass({
queryFixtures: function(fixtures, query){
var properties;
properties = Object.keys(query);
// adding pagination support
if(properties.contains('offset')){
fixtures = fixtures.slice(query.offset, query.offset+query.limit);
}
return fixtures;
}
})
export default Topic;
我在这里做错了什么?
答案 0 :(得分:0)
App.ApplicationAdapter = DS.FixtureAdapter;
应该是:
App.ApplicationAdapter = DS.FixtureAdapter.extend({});
编辑:#1
另外,你得到了什么错误?我没有看到它。
编辑:#2
我想我知道问题在哪里。
您正在尝试覆盖模型定义中的方法,但您应该在适配器类中执行此操作:
App.ApplicationAdapter = DS.FixtureAdapter.extend({
queryFixtures: function() {
...
}
});