Ember 0.9.8.1 Template with ember-data
HTML
<script src="https://github.com/downloads/emberjs/ember.js/ember-0.9.8.1.js"></script>
<script src="https://github.com/downloads/pjmorse/ember-skeleton/ember-data.min.js"></script>
CSS
* { font-family: helvetica; }
body { padding: 20px; }
h1 { font-weight: bold; font-size: 1.2em; }
JavaScript
App = Ember.Application.create();
DS.Model.reopen({
namingConvention : {
keyToJSONKey : function(key) {
return key;
},
foreignKey : function(key) {
return key + "Id";
}
}
});
App.UserSample = DS.Model.extend({
id: DS.attr('number'),
name: DS.attr('string'),
users: DS.hasMany('App.User', {embedded: true})
});
App.User = DS.Model.extend({
id: DS.attr('number'),
name: DS.attr('string'),
userSample: DS.belongsTo('App.UserSample'),
});
App.UserSample.FIXTURES = [
{
id: 1,
name: "Surface Anatomy",
users: [
{
id: 1,
user_sample_id: 1,
name: "String1",
},
{
id: 2,
user_sample_id: 1,
name: "String2",
}]
},
{
id: 2,
name: "Sectional Anatomy"
},
{
id: 3,
name: "Pathways"
},
{
id: 4,
name: "Visual Glossary"
}
];
App.fixtureStore = DS.Store.create({
revision: 4,
adapter: DS.fixtureAdapter
});
App.usrCont = Ember.ArrayController.create();
App.usrCont.set('content', App.fixtureStore.findAll(App.UserSample ));
App.usrCont.get('content').forEach(function(item, idx, en) {
console.log(item.get('name'));
console.log(item.get('users').get('length'));
});