【问题标题】:how to initialize parent template's properties in emberjs controller?如何在 emberjs 控制器中初始化父模板的属性?
【发布时间】:2014-03-03 02:26:21
【问题描述】:

假设我有父应用程序模板,并且在它的出口中有用户模板。现在,当我加载用户路由时,我也想更改应用程序模板的属性,这些属性超出了用户的范围。如何从用户控制器修改应用程序属性?

【问题讨论】:

    标签: templates ember.js properties controller


    【解决方案1】:

    尝试在用户路由的setupController 挂钩中使用controllerFor

    UserRoute = Ember.Route.extend
      setupController: (controller, model) ->
        @_super(controller, model)
    
        @controllerFor('application').set('foo', 'bar')
    

    您也可以查看the needs API

    【讨论】:

    • 非常感谢您的回答。您能否也提供一个needs 的用法示例?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多