mardi 28 juin 2016

Ember multidimensional arrays, best practice with model data

Typically in Ember, you setup your model:

export default Model.extend({
    "name": attr('string'),
    "address": attr('string'),
    "sports": attr()
})

You then create a form:





From there you can get the value of the input or set the value:

var name_val = this.get('name');
var address_val = this.get('address');
var sports_val = this.get('sports');

or set a value:

this.set('address','123 Main Street');

How would one create dynamic multidimensional arrays and store them? For example, you want to list out several sports:

 
 


From there perhaps you want to know given a sport checked, does the user watch that sport, or play that sport? This could be done using a dropdown or more checkboxes. Ultimately, the end result would be this json:

{
    'name':  'Matt',
    'address': '123 Main Street',
    'sports': {
        'baseball': 'watch',
        'hockey': 'play'
    }

}

It seems Ember is easy to setup items one level deep, but what about multi, dynamic values and levels?




Aucun commentaire:

Enregistrer un commentaire