ember-data DS.RESTAdapter导致TypeError [英] ember-data DS.RESTAdapter causes TypeError

查看:144
本文介绍了ember-data DS.RESTAdapter导致TypeError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ember数据的Ember.js,并且定义了以下应用程序:

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆