Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ember-data DS.RESTAdapter causes TypeError

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?

like image 906
Brian Hicks Avatar asked May 03 '26 05:05

Brian Hicks


1 Answers

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 [].

like image 155
tvon Avatar answered May 05 '26 19:05

tvon