vendredi 23 septembre 2016

Ember find model by Id

In my Ember app, I have a complex model that looks like below (kind of contains 2-dimensional array)

[
    [
        {
            id: 'Section1_123',
            label: 'abc'
        },
        {
            id: 'Section1_456',
            label: 'xyz'
        }
    ]
],
[
    [
        {
            id: 'Section2_123',
            label: 'abc'
        },
        {
            id: 'Section2_456',
            label: 'xyz'
        }
    ]
]

There are a lot of other attributes, but this is the overall structure.

Now my question is can I drill-down & find a specific object. It has unique ids (as shown in the example above)

So I need something like model.findBy(Id) I then need to change/set some values for that object. Say I want to change the obj.label from 'abc' to 'abc_NEW'

Just to add, The main model is actually a simple JS array...but the inside objects (e.g. those with id: 'Section1_123', etc) are actually Ember objects




Aucun commentaire:

Enregistrer un commentaire