2014-07-15 90 views
1

我這樣做:模型掛鉤,this.store.find()失敗

App.AccountsRoute = Ember.Route.extend({ 
    model: function() { 
    return this.store.find('Account', {company: 'Blah'}); 
    } 
}); 

但總是得到一個錯誤信息:

Error while processing route: accounts Cannot read property 'map' of undefined TypeError: Cannot read property 'map' of undefined 
    at s.map (http://localhost/public/bower_components/ember/ember.min.js:10:14956) 
    at Ember.Object.extend.pushMany (http://localhost/public/bower_components/ember-data/ember-data.min.js:10:6083) 
    at c.extend.load (http://localhost/public/bower_components/ember-data/ember-data.min.js:9:19306) 
    at http://localhost/public/bower_components/ember-data/ember-data.min.js:9:31635 
    at a (http://localhost/public/bower_components/ember/ember.min.js:12:1824) 
    at i (http://localhost/public/bower_components/ember/ember.min.js:12:1743) 
    at c (http://localhost/public/bower_components/ember/ember.min.js:12:2476) 
    at http://localhost/public/bower_components/ember/ember.min.js:13:11367 
    at e.invoke (http://localhost/public/bower_components/ember/ember.min.js:11:24893) 
    at Object.e.flush (http://localhost/public/bower_components/ember/ember.min.js:11:25401) ember.min.js:10 
n.function.n.apply.r ember.min.js:10 
A.error ember.min.js:18 
i ember.min.js:18 
s ember.min.js:19 
e.trigger ember.min.js:19 
(anonymous function) ember.min.js:19 
a ember.min.js:12 
i ember.min.js:12 
h ember.min.js:12 
(anonymous function) ember.min.js:13 
e.invoke ember.min.js:11 
e.flush ember.min.js:11 
t.end ember.min.js:11 
(anonymous function) 

如果我擺脫了查詢參數的,即:

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

然後一切正常。我使用的是ember 1.6.0和ember-data 1.0.0-beta8。我已經嘗試了幾個不同的版本,以防發生錯誤,但無法解決問題。

任何想法有什麼不對?

+0

糟糕的JSON響應,你會介意添加JSON,當你用查詢做它返回? – Kingpin2k

回答

0

你的查詢/查找所有響應的json響應應該是一個集合。在你的情況下,它應該看起來像這樣:

{ 
    accounts:[ 
    { 
     id:1, 
     company:'Blah' 
    }, 
    { 
     id:2, 
     company:'Blah' 
    } 
    ... 
    ] 
} 

此外,你應該在傳入類型時使用小寫。

this.store.find('account'); 
+0

但我沒有機會看看結果。該錯誤發生在 –

+0

它正在向服務器發出請求之前? – Kingpin2k

+0

不,我正在使用燈具 –