gpt4 book ai didi

ember.js - 如何从 Controller Action 内部获取父路由模型?

转载 作者:行者123 更新时间:2023-12-04 18:43:31 24 4
gpt4 key购买 nike

在我下面的“约会” route ,我可以伸手获取父“日”的模型

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" });
});
});
});

但是,当我深入新路由或编辑路由时,我如何才能(从操作处理程序中)到达并像在路由中那样获取父“day”模型?
App.AppointmentsEditController = Ember.Controller.extend({                
actions: {
updateAppointment: function(appointment) {
var day = this.get('??');
}
}
});

更新

最终的 Controller 代码现在看起来像这样
App.AppointmentsEditController = Ember.Controller.extend({       
needs: 'day',
actions: {
updateAppointment: function(appointment) {
var day = this.get('controllers.day');
}
}
});

最佳答案

Toran - 很抱歉将其添加为额外答案,我还不能发表评论 - 是的,它应该是免费的。您可以访问 controllers.post从内部actions像这样阻止:

var postController = this.get('controllers.post')

关于ember.js - 如何从 Controller Action 内部获取父路由模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19395540/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com