emberjs-在较大的模板中有条件地呈现模板

emberjs - Conditionally rendering templates within a larger template

本文关键字:有条件 emberjs-      更新时间:2023-10-29

Ember Community Assemble!

我想在application.hbs侧边栏中有条件地{{render"}}个小模板,但该侧边栏的内容取决于我们要路由到哪个模型的hb。例如,"permit"侧边栏的属性与"profile"侧边栏不同。

现在,无论选择了什么型号的.hbs,我都只能一次呈现所有侧边栏内容。

<!-- Right Sidebar in application.hbs START -->
    <div id="sidebar-wrapper" class="super-super-float-right-col">
      <div id="sidebar-wrapper" class="super-float-right-col">
        <div id="sidebar-wrapper" class="float-right-col">
          {{render 'applicant'}} <!-- only available to '/person/#' -->
          {{render 'location'}} <!--  only available to '/permit/#' -->
        </div>
      </div>
    </div>
<!-- Right Sidebar END -->
    <div class="The rest of the content">
      {{outlet}} <!--inserts the rest of the html into the main content container -->
    </div>

我不希望"申请人"answers"地点"与上面的同时呈现,我希望根据"人员"的id号更改"申请人"内部的数据。同样的关系也适用于"permission.hbs"内部的"location"

VpcYeoman.PermitRoute = Ember.Route.extend({
    renderTemplate: function() {
        this.render({ render:'location'});
    }
});

Application_route.js目前为空

尽管1.2.0引入了在{{view}}中使用模板名称属性的功能,但它还不适用于{{render}}

因此,如果可以的话,您可以选择使用{{view}},或者模板中的一系列{{#if}},或者组件/视图来包装对渲染内容的选择(一种方法是为每个渲染都有一个模板,以及一个将templateName属性绑定到parentController属性的选项视图,该属性决定了应该显示哪个)

这是我曾经实验过的一个jsbin。