Created
June 8, 2014 21:44
-
-
Save troyscott/4ebf431c8be1e8c5ccc1 to your computer and use it in GitHub Desktop.
Example of a simple EmberJS application that returns a list of contacts from the local memory database (fixture adapter) or from a RESTful service if the fixture adapter is commented out. Click here for the template: https://gist.github.com/troyscott/290611f8f72a2fa7a95a
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App = Ember.Application.create(); | |
// Local In Memory Data Store | |
// Comment this out to defualt to the RESTful Adapter | |
App.ApplicationAdapter = DS.FixtureAdapter; | |
App.Contact = DS.Model.extend({ | |
first: DS.attr(), | |
last: DS.attr(), | |
phone: DS.attr() | |
}); | |
// Seed the In Memory database | |
App.Contact.FIXTURES = [ | |
{ id: 1, first: 'Bob', last: 'Smith', phone: '(777) 999 9999'}, | |
{ id: 2, first: 'Jane', last: 'Smith', phone: '(888) 555 4444'} | |
] | |
// Router | |
App.Router.map(function() { | |
this.resource('contacts', function() { | |
this.resource('contact', { path: '/contacts_id' }, function() { | |
this.route('edit'); | |
}); | |
this.route('create'); | |
}); // users | |
}); // router | |
// Users | |
App.ContactsRoute = Ember.Route.extend({ | |
model: function() { | |
return this.store.find('contact'); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment