I'm trying to get a list of items served from Django and Tastypie and display them using Ember.js. I've encountered the following problem:
EmberJS stores only the last value from JSON - so /api/post serves a few entries, but EmberJS stores and then displays only the last one(I also checked with the Ember extensions for Chrome). I'm not even sure where to look for a solution - is it Ember, Ember-data, Tastypie or all of them?
Here's the javascript code:
Blog.ApplicationAdapter = DS.DjangoTastypieAdapter.extend({
host: "http://127.0.0.1:8000",
namespace: "api/v1"
});
Blog.ApplicationSerializer = DS.DjangoTastypieSerializer.extend({});
/* Models */
Blog.Post = DS.Model.extend({
title: DS.attr('string'),
body: DS.attr('string'),
added: DS.attr('date'),
created: DS.attr('date')
});
/* Routes */
Blog.Router.map(function() {
this.route('post-list');
this.route('post', { path: 'post_id' });
});
Blog.IndexRoute = Ember.Route.extend({
redirect: function() {
this.transitionTo('post-list')
}
});
Blog.PostListRoute = Ember.Route.extend({
model: function() {
return this.store.find('post')
}
});
Here's the curl extract for reference:
{"meta": {"limit": 20, "next": null, "offset": 0, "previous": null, "total_count": 2}, "objects": [{"added": "2014-12-23T19:49:28.881759", "body": "hsdkfkjahsdkshufy \r\n\r\nLorem ipsum", "created": "2014-12-23T19:49:28.881759", "id": 2, "resource_uri": "/api/v1/post/2", "slug": "jklshfkjasfhkjkhlf", "title": "jkl;shfkjasfhkjkhlf"}, {"added": "2014-12-23T23:00:23.719586", "body": "sdhkjasgaskg slkhs;fas\r\n\r\nhsdkjhsask sfhjask \r\nhakjhagkl\r\n\r\nhgaskjhagskj \r\nhgkjash", "created": "2014-12-23T23:00:23.719586", "id": 3, "resource_uri": "/api/v1/post/3", "slug": "asfhklasdnhjasdkghskl", "title": "asfhklasdnhjasdkghskl"}]}
Aucun commentaire:
Enregistrer un commentaire