I'm currently using "ember-1.0.0-rc.7.js" to manage the persistence and data storage for my ember application.
user.js
App.User = DS.Model.extend({
firstName: DS.attr('string'),
lastName: DS.attr('string'),
category: DS.attr('string'),
status: DS.attr('string'),
position: DS.attr('string'),
fullName: function()
{
return '%@ %@'.fmt(this.get('firstName'), this.get('lastName'))
}.property('firstName', 'lastName')
});
App.User.FIXTURES =
[
{
id: 1,
firstName: 'Derek',
lastName: "H",
category: "admin",
status: "offline",
position: "3232"
},
{
id: 2,
firstName: 'Jim',
lastName: "H",
category: "admin",
status: "online",
position: "322"
}
];
UserListController.js
App.UserListController = Ember.ArrayController.create({
content: [],
users: App.User.find()
});
store.js
App.Store = DS.Store.extend({
revision: 12,
adapter: 'DS.FixtureAdapter'
});
From the above, I assumed that App.User.find() would return me all the users. However, I get the following error:
Error From Firebug:
Your application does not have a 'Store' property defined. Attempts to call 'find' on model classes will fail. Please provide one as with 'YourAppName.Store = DS.Store.extend()'
TypeError: store is undefined
The message doesn't make sense, but the store is defined for App. If the store was not defined, then the below code would not work.
In the below code, I call App.User.find() within the context of the route and it works.
router.js
Bib.Router.map(function () {
this.resource('index', { path: '/' });
});
App.IndexRoute = Ember.Route.extend({
model: function () {
return ['a','b', 'c' ];
},
renderTemplate: function () {
this.render();
this.render('userList', { outlet: 'userList', into: 'application', controller: App.UserListController });//render the list in list outlet
},
setupController: function (controller, model)
{
controller.set('menu', model);
controller.set('test', App.User.find());
}
});
In the index.html
<script type="text/x-handlebars" id="userList" data-template-name="userList">
{{#each controller}}
{{firstName}}
{{/each}}
</script>
I want the contoller there to represent the UserListController and have it have a reference to the User Model. Keep in mind I can't hook this up in the route since I only have one route for this application.
I believe this is due to the context in which I'm making the call. In other words, using it within the Controller.I'm probably not understanding a fundamental concept how controllers and models are related.
Any advice appreciated, Thanks, D
.find()
- intuitivepixel