I use the lastest emberjs 1.0 pre4.
In App.FormController, I insert a childView to a containerView:
containerView.get('childViews').pushObject(
App.FieldData4MultipleChoiceView.create()
);
In this childView, I try to print “me.get(‘controller’)”:
didInsertElement: function() {
var me = this;
$(".fieldset.group").on("click", ".fieldChoice img", function(e){
var controller = me.get('controller');
console.log(controller); // line A
});
}
Question 1:
Why “line A” return an instance of App.ApplicationController class but not App.FormController?
Question 2:
How can I get single instance of App.FormController in any other view (not just the view under App.FormController)?
Thanks a lot!
Your example says “In App.FormController, I insert a childView to a containerView” but it’s not clear how that containerView came to exist or what it’s context is. That childView will inherit the context of it’s parent, so my guess is that containerView itself does not have
App.FormControlleras it’s controller.You can’t, at least not without really hacking ember’s internal APIs. This is by design. Each view should be really lightweight and depend only on it’s corresponding controller. That controller can bind to App.FormController or one of it’s properties, but the view does not need to be aware.