ember数据未定义模型中的ID

时间:2014-09-11 02:35:02

标签: ember.js ember-data django-rest-framework

我目前将此作为我的模特

GalacticEmber.Testdata = DS.Model.extend({ username: DS.attr('string'), phone: DS.attr(), last: DS.attr('string'), first: DS.attr('string') });

这是我的路线

GalacticEmber.IndexRoute = Ember.Route.extend({
model: function(){
    return Ember.RSVP.hash({
        testdatum: this.store.find('testdata'),

    });
},
setupController: function(controller, model){
    controller.set('content', model.testdatum);
}
});

但是当我导航到我的页面时,我收到此错误?

"加载路线时出错:未定义"

我可以在site.com/api/testdatum中导航到我的网站(这是结果django REST)

{
"testdata": [
    {
        "username": "bba1", 
        "phone": 55522114, 
        "last": "abbbla", 
        "first": "bob"
    }, 
    {
        "username": "ema1", 
        "phone": 9998887765, 
        "last": "hobart", 
        "first": "johnston"
    }
]
}

我知道没有" id"因为它来自NoSQL数据库。所以我在models.js文件中也有这一行

GalacticEmber.TestdataSerializer = DS.RESTSerializer.extend({
primaryKey: 'username'
});

控制台错误的堆栈跟踪::

Error while loading route: undefined ember.js:3285
logToConsole ember.js:3285
defaultActionHandlers.error ember.js:33921
triggerEvent ember.js:33996
trigger ember.js:32823
Transition.trigger ember.js:32044
handleError ember.js:33157
invokeCallback ember.js:9427
publish ember.js:9097
publishRejection ember.js:9525
DeferredActionQueues.flush ember.js:5650
Backburner.end ember.js:5741
Backburner.run ember.js:5780
Ember.run ember.js:6181
hash.error ember-data.js:8671
fire jquery.min.js:3048
self.fireWith jquery.min.js:3160
done jquery.min.js:8237
callback

我错过了什么?

谢谢!

1 个答案:

答案 0 :(得分:0)

'GalacticEmber.IndexRoute = Ember.Route.extend({
    model: function(){
      return Ember.RSVP.hash({
    testdatum: this.store.find('testdata'),

    });
 },
 setupController: function(controller, model){
controller.set('content', model.testdatum);
 }}
 );'

试试

 `GalacticEmber.IndexRoute = Ember.Route.extend({
 model: function(){
    return this.store.findAll('testdata'),

});
 },
 setupController: function(controller, model){
controller.set('content', model.testdatum);
}
 });`

我不知道你为什么试图将它包含在Promise中,默认是它的承诺。