在我下面的“约会”路线中,我可以到达并获得父母“日”的模型
App.Router.map(function(match) {
this.resource("day", { path: "/day/:day" }, function() {
this.resource("appointments", { path: "/appointments" }, function() {
this.route("new", { path: "/:appointment_start/new" });
this.route("edit", { path: "/:appointment_id/edit" });
});
});
});
但是当我深入到新的或编辑路线时,我怎样才能到达(从动作处理程序中)并像我在路线中那样抓住父“天”模型?
App.AppointmentsEditController = Ember.Controller.extend({
actions: {
updateAppointment: function(appointment) {
var day = this.get('??');
}
}
});
更新
最终控制器代码现在看起来像这样
App.AppointmentsEditController = Ember.Controller.extend({
needs: 'day',
actions: {
updateAppointment: function(appointment) {
var day = this.get('controllers.day');
}
}
});
答案 0 :(得分:4)
Toran - 抱歉添加这个作为额外的答案,我还不能评论 - 是的,它应该免费工作。您可以在controllers.post
块中访问actions
,如下所示:
var postController = this.get('controllers.post')
答案 1 :(得分:2)
有简单的方法可以做到这一点。在AppointmentsEditController
添加
needs: "day"
然后,您可以通过day
访问this.get('controllers.day')
控制器。
我总是使用这样的东西:
App.CommentsControler = Ember.Controller.extend({
needs: "post",
postBinding: "controllers.post",
...
postName: function() {
return this.post.name;
}.property("post.name")
})
看一下这篇文章http://emberjs.com/guides/controllers/dependencies-between-controllers/
我希望这有帮助:)