Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember.js how to load an array of simple ember objects

Tags:

ember.js

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?

like image 640
dagda1 Avatar asked Jun 07 '12 13:06

dagda1


2 Answers

I'd map instead of using forEach:

pojos.map(function(obj){
  return Ember.Object.create().setProperties(obj);
});
like image 174
ebryn Avatar answered Nov 15 '22 10:11

ebryn


Yep:

var ret = pojos.map(function(data) { return Ember.Object.create(data); });
like image 41
Mike Aski Avatar answered Nov 15 '22 09:11

Mike Aski