gpt4 book ai didi

Ember.js:将子资源的 View 插入主应用程序的导出

转载 作者:行者123 更新时间:2023-12-04 16:47:22 25 4
gpt4 key购买 nike

默认情况下,Ember 将子资源的 View 插入到 {{outlet}} 中。由父资源的 View 定义。我如何覆盖它?即在 {{outlet}} 中插入 subview 由应用程序 View 定义。为什么这是默认设置?

用例:有一个users资源,带有 new里面的路线。我想要 new在应用程序中显示 {{outlet}}而不是父资源的 {{outlet}} .

App.Router.map(function(){
this.resource('users', function(){
this.route('new');
});
});

最佳答案

对于每条路线,我们都有一个 renderTemplate我们可以重载的方法。这使我们可以完全控制 View 的渲染。

例如,我们可以指定进入哪个 {{outlet}} View 将呈现为 into :

(我假设这是您的用例,但我今天有点心不在焉。)

var UsersRoute = Ember.Route.extend({
renderTemplate: function() {
this.render('users', {
// Render the UsersView into the outlet found in application.hbs
into: 'application'
});
}
});

我们还可以使用 outlet 指定要渲染的 socket 名称。属性(property):
var UsersRoute = Ember.Route.extend({
renderTemplate: function() {
this.render('users', {
// Render the UsersView into the outlet named "sidebar"
outlet: 'sidebar'
});
}
});

当然,我们可以使用两者的组合来指定 socket 的名称,以及使用 into 找到该 socket 的位置。属性(property)。

关于Ember.js:将子资源的 View 插入主应用程序的导出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14625709/

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