我正在尝试获取Django和Tastypie提供的项目列表,并使用Ember.js显示它们。我遇到了以下问题:
EmberJS只存储JSON中的最后一个值 - 所以/ api / post会提供一些条目,但EmberJS会存储然后只显示最后一个(我还检查了Chrome的Ember扩展名)。我甚至不确定在哪里寻找解决方案 - 是Ember,Ember-data,Tastypie还是所有这些?
这是javascript代码:
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')
}
});
这是卷曲提取物供参考:
{
"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"
}
]
}
答案 0 :(得分:0)
我使用最新的Django版本(从1.6到1.7)重新创建了项目。似乎问题现在已经解决,代码没有变化。