I’m trying to load some JSON from the backend and initiate a model. So far, I think I get the model, but without its properties set 🙁
Here is my test code:
window.App = Ember.Application.create();
App.Router.map(function() {
this.resource('person', { path: '/people/:person_id' });
});
App.Adapter = DS.RESTAdapter.extend({
namespace: '~user1/embertest'
});
App.Store = DS.Store.extend({
revision: 11,
adapter: App.Adapter,
});
var attr = DS.attr;
App.Person = DS.Model.extend({
firstName: attr('string'),
lastName: attr('string')
});
App.PersonRoute = Ember.Route.extend({
model: function(params) {
return App.Person.find(params) ;
}
});
App.PersonController = Ember.Controller.extend({
contentDidChange: function() {
debugger ;
console.info(this.get('content'));
}.observes('content.isLoaded')
}) ;
And the data is loaded from a json file which only contains:
{"persons": {"firstName": "Jeff","lastName": "Atwood"}}
Now, with the url localhost/~user/embertest.html#people/10 I see that the data gets loaded and the controller method contentDidChange gets called. But when I do
this.content.get("firstName") ; // or this.get("content").get("firstName")
it returns “undefined”. What is going wrong here ?
Finally, here are my templates which are in the :
<script type="text/x-handlebars" data-template-name="person">
Person: {{content.firstName}}
</script>
<script type="text/x-handlebars" data-template-name="application">
{{outlet}}
</script>
Cheers
try to remove the PersonRoute, the default model hook should be fine. I think what’s going on here is that App.Person.find(params) send a findQuery() instead of a find(id).