1

My issue is to get the content from an ember embedded hasmany array object.

I am using ember model (https://github.com/ebryn/ember-model) library to get and post data from the server.

The JSON returned contains embedded objects, but in my view, I cannot get the data from this embedded record.

Following is the json structure and my code.

JSON:

[
    {
        "id": 1,
        "ModuleID": "one",
        "SubModules": [
            {
                "id": 1,
                "Data": "content"
            },
            {
                "id": 2,
                "Data": "content"
            }
        ]
    },
    {
        "id": 2,
        "ModuleID": "six",
        "SubModules": []
    }
]

Models:

App.Mod = Ember.Model.extend({
    ModuleID: Ember.attr(),
    SubModss: Ember.hasMany('App.Components', { key: 'SubModules', embedded: true })
});

App.Components = Ember.Model.extend({
    ModuleID: Ember.attr(),
    Data: Ember.attr()
});

Index Route: Get all the module objects

App.IndexRoute = Ember.Route.extend({
    model: function () {
        return App.Mod.findAll();
    }
});

Index.hbs Template:

    <ul>
        {{#each item in model}}
            {{#each obj in item.SubModss}}
              <p>{{obj.Data}}</p>
            {{/each}}
        <li> {{#link-to "module" item}} {{item.ModuleID}} {{/link-to}} </li>
        {{/each}}
   </ul>

Is that the correct way to get the elements of "SubModules"?The second each loop is not working, and calling item.SubModss returns Ember.EmbeddedHasManyArray.

Akk
  • 406
  • 1
  • 5
  • 17

0 Answers0