harlan
harlan

Reputation: 3

Ember.js - controlling embedded/aggregate model creation

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

Answers (1)

Mike Aski
Mike Aski

Reputation: 9236

You should indeed use ember-data.

Upvotes: 1

Related Questions