What is the best way of creating an array of ember objects from an array of json objects objects?
I can use SetProperties on each individual object like this:
var ret = Ember.A();
pojos.forEach(function(obj){
var em = Ember.Object.create({});
emCluster.setProperties(obj);
ret.push(emCluster);
});
But is there a one line way of obtaining the same result?
I'd map
instead of using forEach
:
pojos.map(function(obj){
return Ember.Object.create().setProperties(obj);
});
Yep:
var ret = pojos.map(function(data) { return Ember.Object.create(data); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With