I'm trying to set this up so that I can query my fixtures, but I get the above error. In app.js, I have:
App.ApplicationAdapter = DS.FixtureAdapter;
Here's my model method for the index route:
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')
})
});
}
And the topic.js model:
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;
What am I doing wrong here?
Aucun commentaire:
Enregistrer un commentaire