我是 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/