Emberjs使用{{action ???渲染模板上= “的focusIn”}}

时间:2014-01-08 20:12:46

标签: javascript templates ember.js rendering action

当用户点击并定位该页面主要内容中的标题时,我想在名为“workflow_editor_sidebar.hbs”的侧栏.hbs文件中呈现“we-is-app-complete.hbs”(' workflow_editor.hbs'),但我不想改变目前的路线。

我尝试{{action on =“focusIn}}但是我没有在workflow_editor_controller.js中定义一个函数来放在'action'和'on ='之间。让我们调用这个未定义的函数'renderIsAppCompleteTemplate:'

如果选择了不同的标题,侧边栏将隐藏'we-is-app-complete.hbs'并呈现新模板,但是对于此示例,我们将只关注'we-is-app-complete。 HBS'

在'we-is-app-complete.hbs'

<h2> This is the code that I want to render.</h2>

在'workflow_editor_sidebar.hbs'

{{#if 'renderIsAppCompleteTemplate}
  {{render 'we-is-app-complete.hbs}}
{{/if}}

在'workflow_editor.hbs'=='/ workflow_editor / new'

<div {{ action 'renderIsAppCompleteTemplate' on="focusIn" }} class="fees-container collapsible">
  <div class="arrow-nav collapsibleHeader fees-edit-selection">
    <h2>Permit Fees 
      <h4 class="inline-block"> ((#)) of Calculations</h4>
    </h2>
    <img src="images/menu.png" class="menu-icon" id="m1">
  </div>
</div>

在'workflow_editor_controller.js'

VpcYeoman.WorkflowEditorController = Ember.ObjectController.extend({
  renderisAppCompleteTemplate: function() {
   */ nothing yet */
})

随意建议替代或更有效的方法来解决这个问题。

编辑:我通过基于当前渲染侧边栏模板做了类似的事情。这是代码,如果它激发任何灵感。

对于控制器

  showRecordBasedOnRoute: function(){
    var curPath =this.get('currentPath');
    if(curPath == 'application'){
      return false;  
    } else if (curPath == 'record'){
     return true; 
    } //other things
  }.property('currentPath'),

&安培;&安培;

      {{#if showRecordBasedOnRoute}}
        {{render 'record-sidebar'}}
      {{/if}}  

1 个答案:

答案 0 :(得分:1)

不幸的是,您当时只能拥有一条有效路线。我有同样的问题。有一个实验版本,让你使用一个独立路由的子路由器,但它不值得麻烦。

您目前正在做的工作正常。但是,您需要在操作对象中定义操作。

VpcYeoman.WorkflowEditorController = Ember.ObjectController.extend({
  actions: {
    renderisAppCompleteTemplate: function() {
      */ nothing yet */
    }
  }
})