2014-04-03 48 views
0

我得到我的第一次Ember.js應用以下錯誤用Node.js的後端的特性「店」:灰燼關係:類型錯誤:無法設置未定義

Intermediate-transitioned into 'loading' ember-1.5.0.js:3521 
Error while loading route: TypeError: Cannot set property 'store' of undefined 
at DS.Store.Ember.Object.extend.modelFor (http://127.0.0.1:5555/js/libs/ember-data.js:2986:31) 
at DS.Store.Ember.Object.extend.recordForId (http://127.0.0.1:5555/js/libs/ember-data.js:2437:29) 
at deserializeRecordId (http://127.0.0.1:5555/js/libs/ember-data.js:3355:35) 
at http://127.0.0.1:5555/js/libs/ember-data.js:3333:21 
at http://127.0.0.1:5555/js/libs/ember-data.js:7117:30 
at http://127.0.0.1:5555/js/libs/ember-1.5.0.js:3428:30 
at Object.OrderedSet.forEach (http://127.0.0.1:5555/js/libs/ember-1.5.0.js:3271:24) 
at Object.Map.forEach (http://127.0.0.1:5555/js/libs/ember-1.5.0.js:3426:22) 
at Function.DS.Model.reopenClass.eachRelationship (http://127.0.0.1:5555/js/libs/ember-data.js:7116:50) 
at normalizeRelationships (http://127.0.0.1:5555/js/libs/ember-data.js:3319:18) ember-1.5.0.js:3521 
Transition #0: games: transition was aborted 

以下JSON得到由返回/遊戲

{ 
    "games": [ 
    { 
     "serverSeedHash": "5eb59053dcb5810322e367245f631a65589ddf7bbe950d2986a43a5f376312ef", 
     "id": 2, 
     "serverSeed": null, 
     "table": [ 
     1 
     ], 
     "amountOfPlayers": 2, 
     "prizePool": 39600 
    } 
    ], 
    "tables": [ 
    { 
     "id": 1, 
     "minimumPlayers": 2, 
     "maximumPlayers": 100, 
     "cardPrice": 1000, 
     "games": [ 
     2 
     ] 
    } 
    ] 
} 

我完全Ember.js app.js看起來是這樣的:

window.App = Ember.Application.create({ 
    LOG_TRANSITIONS: true, 
    LOG_TRANSITIONS_INTERNAL: true 
}); 

App.Router.map(function() { 
    this.route('games', { path: '/' }); 
}); 

App.Game = DS.Model.extend({ 
    serverSeedHash: DS.attr(), 
    serverSeed: DS.attr(), 
    amountOfPlayers: DS.attr(), 
    prizePool: DS.attr(), 
    table: DS.belongsTo('table') 
}); 

App.Table = DS.Model.extend({ 
    minimumPlayers: DS.attr(), 
    maximumPlayers: DS.attr(), 
    games: DS.hasMany('game') 
}); 


App.GamesRoute = Ember.Route.extend({ 
    model: function() { 
     return this.store.find('game'); 
    } 
}); 

沒有人有任何想法,爲什麼我收到一個錯誤?請注意,這是我第一次玩弄Ember.JS。 過去幾天我一直在打破這一切。

回答

1

在您的game模型中,您將table定義爲belongsTo的關係,因此Ember期望在將數組發送給它時它是單數。改變你的對象到這個,它應該工作:

{ 
    "games": [ 
    { 
     ... 
     "table": 1, 
     ... 
    } 
    ], 
    "tables": [ 
    ... 
    ] 
} 
+0

不幸的是,這並沒有解決問題。 我忘了說,代碼在我開始定義關係之前確實有效。所以在添加App.Table模型後,它打破了。 – Martijn

+1

好的。仔細觀察,您將Game模型中的'table'定義爲單​​獨的'belongsTo'關係,但是您將它發送給一個表格陣列。如果你只是發送'... table:1,...',它能修復它嗎? – EmptyArsenal

+0

修好了...... 說真的,我早該問別人了,對這麼少的東西感到非常沮喪。 – Martijn

相關問題