EmberJS:如何在选择更改时呈现模板
EmberJS: How to render a template on select change
我是 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"}}
当位置类型更改时,将在控制器中触发位置类型更改函数。但是如何从那里将一些内容渲染到 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')
});
将路线中的操作作为
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
如果您只需要显示一个框架,当存在选定的内容时,您可以使用if
车把助手:
在您的模板中
...
{{#if selectedLocationType}}
Any content here will be visible when selectedLocationType has some value
{{/if}}
...
{{view Ember.Select
contentBinding="model"
selectionBinding="selectedLocationType"
optionValuePath="content.id"
optionLabelPath="content.name"}}
我希望它有所帮助
相关文章:
- 下拉选择可自动更改第二个下拉选择
- 如何使用jQuery选择下拉列表的值
- Emberjs应用程序加载在除Index之外的所有路由上
- jquery点击函数select&取消选择
- Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式
- 按照选项卡索引的顺序循环一个jQuery选择
- 在动态创建的元素上获取对特定选择器的引用
- AngularJS-在JSON选择器中使用变量名
- 每当您在选择器内移动鼠标时,悬停功能就会重复
- 获取选择框的状态
- d3基于用户选择动态更新节点
- 提交后保留下拉选择的值
- JQuery对动态创建的对象进行选择
- jQuery Mobile;Emberjs-选择小工具
- EmberJS ArrayControlller 在排序后重置选择
- CKEditor 未捕获的类型错误:无法在具有多个编辑器的 EmberJS 单页应用程序中调用 null 的“不可选择”
- EmberJS:如何在选择更改时呈现模板
- EmberJS -设置选择视图的默认值
- Emberjs选择绑定
- 使用emberjs选择视图填充选择框