簡體   English   中英

ember.js - 在router.js中為控制器提供模板

[英]ember.js - render a template in router.js equivalent for controllers

在ember中,有沒有辦法將模板渲染到控制器的插座中,以獲得所需的效果:

this.render('some_template', {
  into: 'template_name',
  outlet: 'template_outlet'
});

或者更好的是,從控制器調用router.js中的動作?

你可以把一個方法放在動作哈希下的控制器的相應路由中(例如:posts.index controller和posts.index route)並使用send調用它

posts.index控制器

this.send('exampleAction', record);

posts.index路線

actions: {
  exampleAction: function(record){
       console.log(record);
  }
}

您可以使用組件代替插座:

<script type="text/x-handlebars" id="components/x-outlet">
  {{ partial template }}
</script>

然后,在控制器中,您可以擁有一個template屬性,您可以將其傳遞給組件以動態顯示模板:

App.IndexController = Ember.ArrayController.extend({
  template: function(){
    return 'this_one';
  }.property(),

  actions: {
    that_one: function(){
      this.set('template', 'that_one');
    }
  }
});

這里的工作示例

不完全確定你的意思

或者更好的是,從控制器調用router.js中的動作?

但如果您只是想嘗試轉換到不同的路徑,可以使用transitionToRoute()方法(參見此處

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM