Playing around with ember, I found that sometimes the model is stored on the controller's content
property, sometimes the model is directly available on the controller as well. I do not understand however, when this is the case.
Let me explain it by an example which I found when assembling my ember MVC.
Setup A - The start
Member
object, corresponding MemberRoute
, MemberView
classes and a template with the name member
. Member
object had some attributes such as id
, nickname
, etc.MemberController
was defined, thus by ember's convention, it provides the controller on its own.Setup B - The customization
MemberController
defined that contains some action methods that are triggered from within the template.The strange behaviour (resp. what I do not completely understand)
Member
's attributes directly with {{id}}
or {{nickname}}
.{{content.id}}
or {{content.nickname}}
As documented in ember's documentation, MemberView
does
setupController : function(controller, member) {
controller.set('content', member);
},
So, could somebody help me to understand why the difference and where the difference is? Currently, my guess would be either
or
Any help to understand this is highly appreciated. It already took my quite a while to come as far as this. I first thought it could be the modularization introduced by the project setup with requireJS (well, I still think that could have a influence). Ember is v1.0pre4.
Thanks in advance! Patrick
So, could somebody help me to understand why the difference and where the difference is? Currently, my guess would be either that the context of the template is different (possibly there is a code piece missing in the setup of the controller?) or the default controller that is provided by ember automatically, has some additional magic that is not directly avaiable for customized controllers.
It's hard to say for sure without seeing your code, but my best guess is that your MemberController
extends Ember.Controller
. The default provided by ember (in this scenario) would have been an Ember.ObjectController
. If that's what you want, change your MemberController definition to:
App.MemberController = Ember.ObjectController.extend({
myProperty: 'value'
});
An objectController acts as a proxy to it's content
property, typically that is an ember model. So if things are wired up correctly you should never need to access a model via the 'content` property. If you ever see something like:
{{content.id}} or {{content.nickname}}
it's a sign that you should change to an ObjectController. See EMBER GUIDES: REPRESENTING A SINGLE MODEL! for a more detailed explanation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With