How to access nested object in json with Ember data

前端 未结 3 1947
栀梦
栀梦 2020-12-16 21:19

I\'m using Ember data and having a hard time figuring out get ember to recognize nested properties in my JSON response from the server. This is ember-1.0.0-pre.4.js.

<
相关标签:
3条回答
  • 2020-12-16 21:49

    Looks like sma's answer was correct, I just needed a reference to the adapter first. This bit...

    DS.RESTAdapter.map 'App.School', addr {embedded: 'always' }
    

    ...gives an error 'cannot call map of undefined'. So updated to...

        App.Adapter = DS.RESTAdapter.extend
          bulkCommit: false
    
    
        App.Adapter.map 'App.School', {
          addr: {embedded: 'always'}
        }
    

    Works now!

    0 讨论(0)
  • 2020-12-16 21:52

    Since you're embedding the addr JSON in your schools JSON you need to setup the mapping in the DS.RESTAdapter.

    DS.RESTAdapter.map 'App.School',
      addr: { embedded: 'always' }
    

    The embedded option can have two values, 1) always, 2) load.

    See Yehuda's answer here for the details: https://stackoverflow.com/a/14324532/1409279

    0 讨论(0)
  • 2020-12-16 21:57

    Did you get time to look at

    Ember Data: Model Fragments

    It allows nested data

    0 讨论(0)
提交回复
热议问题