【问题标题】:How to tell Emberjs to render specific templates on a given outlet?如何告诉 Emberjs 在给定的插座上呈现特定的模板?
【发布时间】:2014-02-25 13:27:59
【问题描述】:

我有一个如下所示的 Emberjs 模板:

<script type="text/x-handlebars" data-template-name="content-area">
    <div id="content">
        <div id="side-tree" class="ui-layout-west">
            <!-- components and deployments tree-->
            <div id="componentsTree" data-source="ajax"></div>

        </div>
        <div id="center-content" class="ui-layout-center">
            {{outlet content-area}}

        </div>
    </div>
</script>

我需要根据用户生成的事件将不同的模板呈现到该内容区域插座中。

另外,在渲染这些模板时,我需要传递一些数据以便正确渲染。

在处理这些事件时,如何明确告诉 Ember 将带有特定数据的模板(例如 A 或 B)渲染到内容区域出口?

谢谢!

【问题讨论】:

  • 你传递什么数据?你在渲染什么模板?回答这个问题将有助于引导您朝着正确的方向前进。你可以看看renderTemplate钩子在Route和render方法。

标签: javascript templates ember.js render mustache


【解决方案1】:

看看this的答案。

基本上:

App.SomeRoute = Ember.Route.extend({

    renderTemplate: function() {
        // render the template called A
        this.render('A', {
            into: "application" // inside the application template (or any other already rendered templates)
            outlet: "a" //inside an outlet called a
            controller: "a" //using the controller A
        });

        this.render ....

    },

});

不用说,您可以随意拨打render 多次。此外,controller 也可以是您自己实例化和配置的对象。

希望对你有帮助!

【讨论】:

  • 谢谢,很有帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多