Dan*_*nny 6 javascript jquery handlebars.js ember.js
我是ember的新手,我正试图弄清楚当select控件发生变化时如何渲染模板.
码:
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"}}
Run Code Online (Sandbox Code Playgroud)
当locationType更改时,将在控制器中触发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')
});
Run Code Online (Sandbox Code Playgroud)
在你的路线中采取行动
changeTemplate: function(selection) {
this.render('template'+selection.id,{into:'locationType'});
}
Run Code Online (Sandbox Code Playgroud)
并{{outlet}}在你locationType的模板中有一个.
{{view Ember.Select
contentBinding="model"
selectionBinding="selectedLocationType"
optionValuePath="content.id"
optionLabelPath="content.name"}}
{{outlet}}
Run Code Online (Sandbox Code Playgroud)
根据您的要求提供JSBin示例
| 归档时间: |
|
| 查看次数: |
2321 次 |
| 最近记录: |