Reputation: 3
See sample on JSFiddle.
With Ember.js, is there a way to control model creation from JSON, in particular creation of embedded/aggreates? In example below, would like Person model to contain instances of Friend. In Knockout this is accomplished through the mapping plugin. Would appreciate any suggestions.
Person = Ember.Object.extend({
numberOfFriends : function() {
return this.get("friends").length;
}.property("friends"),
});
Friend = Ember.Object.extend({
isAvailable : function() {
var stat = this.get('status');
return stat == 'online';
}.property('status'),
});
var personData = {
name : "Fozzie Bear",
friends : [
{
name : "Kermit The Frog",
status : "online"
},
{
name : "Miss Piggy",
status : "sleeping"
}
]
};
var person = Person.create(personData);
Upvotes: 0
Views: 290