javascript - EmberJS : How to render a template on select change

标签 javascript jquery ember.js handlebars.js

我是 ember 的新手,正在尝试弄清楚如何在选择控件更改时呈现模板。

代码:

    App.LocationTypeController = Ember.ArrayController.extend({

    selectedLocationType: null,

    locationTypeChanged: function() {
        //Render template
    }.observes('selectedLocationType')
});

{{view Ember.Select 
  contentBinding="model"
  selectionBinding="selectedLocationType"
  optionValuePath="content.id"
  optionLabelPath="content.name"}}

当 locationType 改变时, Controller 中的 locationTypeChanged 函数被触发。 但是我如何从那里将一些内容渲染到 dom 中呢? (this.render()?)...

最佳答案

是的,你必须只使用 this.render(),但这里的关键是它里面的 into 选项。

App.LocationTypeController = Ember.ArrayController.extend({

 selectedLocationType: null,

 locationTypeChanged: function() {
    var selectedLocationType = this.get('selectedLocationType');
    this.send('changeTemplate',selectedLocationType);
 }.observes('selectedLocationType')
});

让你的 route 的 Action 为

changeTemplate: function(selection) {
          this.render('template'+selection.id,{into:'locationType'});
 }

并且在您的 locationType 模板中有一个 {{outlet}}

{{view Ember.Select 
       contentBinding="model"
       selectionBinding="selectedLocationType"
       optionValuePath="content.id"
       optionLabelPath="content.name"}} 

{{outlet}}

样本 JSBin满足您的需求

关于javascript - EmberJS : How to render a template on select change,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18648006/

相关文章:

javascript - 标签云过滤器

ember.js - 将条件类绑定(bind)与现有类结合起来

ember.js - 为什么我必须在简单例份验证自定义 session 上查找存储而不是将其作为服务注入(inject)?

javascript - 侧边栏推送内容

javascript - 使用 onmouseover 将文本超链接更改为图像超链接?

javascript - API数据未显示在页面上

javascript - 防止子窗口被弹出窗口阻止程序捕获

javascript - 咕噜声 : Access YAML symbols in external file

jquery - 简单的Jquery显示隐藏问题

javascript - 来自 ember 数据存储的 ember map 对象