gpt4 book ai didi

javascript - `this._super(controller,model)` 在 Ember 路由器中意味着什么?

转载 作者:数据小太阳 更新时间:2023-10-29 06:11:21 25 4
gpt4 key购买 nike

我在 EmberJS 代码和讨论{未提供引用}中看到以下内容:

代码

路由.js

setupController: function (controller, model) {
this._super(controller,model);
// More code
},

问题

这里对 this._super(controller,model); 的调用是做什么的?

什么时候需要使用这种类型的调用?

只是想在这里学习,因为我的 Nose 因 Ember 学习曲线而流血。

最佳答案

正如@RyanHirsch 所说,this._super 调用该方法的父实现。

setupController的情况下,调用this._super(controller,model)会将 Controller 的'model'属性设置为传入的模型。这是默认实现。因此,一般情况下我们不需要实现该方法。

现在,当我们想为 Controller 设置额外的数据时,我们通常会覆盖它。在那些情况下,我们需要默认行为和自定义内容。所以我们调用 _super 方法。然后做我们的事情。

setupController: function (controller, model) {
// Call _super for default behavior
this._super(controller, model);

// Implement your custom setup after
controller.set('showingPhotos', true);
}

Here is the default implementation of setupController.

关于javascript - `this._super(controller,model)` 在 Ember 路由器中意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28029193/

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