1
votes

Let's assume that I've set everything up correctly. I have a model App.User and I have a controller App.UsersIndexUserController.


GOOD GOOD GOOD GOOD GOOD

The following view template ...

<script type="text/x-handlebars" data-template-name="users_index_template">
  {{#each user in users}}
    {{log user}}
    {{#linkTo users.user user}}{{user.name}}{{/linkTo}}
  {{/each}}
</script>

... this outputs the following in browser's console.log ...

<App.User:ember258> { created_at="2013-03-05T01:51:15Z", id=76 ... etc ... }

BAD BAD BAD BAD BAD

However, when using itemController directive in my template, like so ...

<script type="text/x-handlebars" data-template-name="users_index_template">
  {{#each user in users itemController="usersIndexUser"}}
    {{log user}}
    {{#linkTo users.user user}}{{user.name}}{{/linkTo}}
  {{/each}}
</script>

... this outputs the following in browser's console.log ...

<App.UsersIndexUserController:ember253> { target=<Ember.ArrayController:ember245> ... etc ... }

I'm expecting {{log user}} to return an instance of App.User for both cases. But as you can see above, it returns an instance of App.UsersIndexUserController when using itemController directive, and returns and instance of App.User when not using itemController directive.

Should my App.UsersIndexUserController explicitly return some object such that in both cases above, {{log user}} will return App.User?

App.UsersIndexUserController = Ember.ObjectController.extend({
});

I'm using Ember.js v1.0.0-rc1

// Version: v1.0.0-rc.1
// Last commit: 8b061b4 (2013-02-15 12:10:22 -0800)
1

1 Answers

5
votes

I think this behaviour is right. In the second case you are explicitly telling ember to wrap each of your user objects in a proxy (UsersIndexUserController). Therefore the logging of the variable user yields an instance of this proxy. From a debugging perpspective, i absolutely agree with the behaviour of the log helper. It may not be intuitive at first, but would this be not the case, you would not see the real object you are working on there. Imagine your itemController would define a computed property also called name. In this case {{user.name}} would access the property on the controller instead of the model. This could likely be an error and with this behaviour of the helper, you can spot the error much easier.