ember-data DS.RESTAdapter导致TypeError [英] ember-data DS.RESTAdapter causes TypeError
问题描述
window.App = Ember.Application.create()
App.store = DS.Store.create
修订版:4
适配器:DS.RESTAdapter。创建{bulkCommit:false}
App.Source = DS.Model.extend
#options
primaryKey:'_id'
#fields
name:DS.attr'string'
raw_text:DS.attr'string'
App.sourcesController = Ember.ArrayProxy.create
content:App.store.findAll App.Source
App.ListSourcesView = Ember.View.extend
templateName:'app / templates / sources / list'
sourcesBinding:'App.sourcesController'
该模板如下所示:
< table>
< thead>
< tr>
< th> ID< / th>
< th> Name< / th>
< / tr>
< / thead>
< tbody>
{{#each sources}}
{{view App.ShowSourceView sourceBinding =this}}
{{/ each}}
< / tbody>
< / table>
当我尝试加载 App.ListSourcesView
在我的页面中,我在ember-data.js中收到错误,说:未捕获TypeError:无法读取未定义的属性map
。
我无法弄清楚我做错了什么,在这种情况下,通过源码阅读并没有帮助我的困惑。有没有人经历过这个,或者可以告诉我我已经定义/没有定义不正确?
进入此处。简而言之,ember数据期望资源列表嵌套在资源名称下,例如,如果您获得/ users /,则结果应为 {users:[]}
和不是顶级数组 []
。
I'm trying out Ember.js with ember-data, and I have the following application defined:
window.App = Ember.Application.create()
App.store = DS.Store.create
revision: 4
adapter: DS.RESTAdapter.create { bulkCommit: false }
App.Source = DS.Model.extend
# options
primaryKey: '_id'
# fields
name: DS.attr 'string'
raw_text: DS.attr 'string'
App.sourcesController = Ember.ArrayProxy.create
content: App.store.findAll App.Source
App.ListSourcesView = Ember.View.extend
templateName: 'app/templates/sources/list'
sourcesBinding: 'App.sourcesController'
That template looks like this:
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
</thead>
<tbody>
{{#each sources}}
{{view App.ShowSourceView sourceBinding="this"}}
{{/each}}
</tbody>
</table>
When I try to load App.ListSourcesView
in my page, I get an error in ember-data.js saying: Uncaught TypeError: Cannot read property 'map' of undefined
.
I can't figure out what I'm doing wrong, and reading through the source isn't helping my confusion any in this case. Has anyone experienced this, or can tell me what I've defined/not defined incorrectly?
Possibly the same thing I ran into over here. In short ember-data expects resource lists to be nested under the resource name, eg if you get /users/ then the result should be { "users": [] }
and not a top-level array []
.
这篇关于ember-data DS.RESTAdapter导致TypeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!