Ember Data Mockjax
HTML
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.5.2/jquery.mockjax.js"></script>
<script src="http://ember.alexspeller.com/handlebars-1.0.0.js"></script>
<script src="http://ember.alexspeller.com/ember-latest.js"></script>
<script src="http://ember.alexspeller.com/ember-data-latest.js"></script>
<script type="text/x-handlebars">
<h1>Ember Data Mockjax</h1>
{{render "foos" this.bars}}
</script>
<script type="text/x-handlebars" data-template-name='foos'>
<h2>In controller</h2>
<ul>
{{#each}}
<li>Foo: {{this.id}}</li>
{{/each}}
</ul>
</script>
JavaScript
window.App = Em.Application.create()
App.Store = DS.Store.extend({
adapter: DS.FixtureAdapter
});
App.Bar = DS.Model.extend({});
App.Bar.FIXTURES = [{ id: 1 }, { id: 2 }, { id: 3 }];
App.Foo = DS.Model.extend({
bars: DS.hasMany('bar', { async: true })
});
App.Foo.FIXTURES = [{
id: 1,
bars: [1, 2, 3]
}];
App.ApplicationController = Em.ObjectController.extend({});
App.FoosController = Em.ArrayController.extend({});
App.ApplicationRoute = Ember.Route.extend({
model: function(){
var foo;
return this.store.find('foo', 1)
.then(function(f){
foo = f;
return foo.get('bars');
})
.then(function(){
return foo;
});
}
});