ember.js - 在 Ember.Select 中选择值时更新值

标签 ember.js ember.select

我的模板中有一个 Ember.Select 和一个图像:

Difficulty: {{view Ember.Select id="id_diff" contentBinding="difficulties" optionValuePath="content.id" optionLabelPath="content.title"}}
<img src="(path)" />

选择填充来自服务器的值;在 Controller 中:

difficulties: function() {
    return this.get('store').find('difficulty');
}.property()

和型号:

Gmcontrolpanel.Difficulty = DS.Model.extend({
    title: DS.attr('string'),
    description: DS.attr('string'),
    path: DS.attr('string')
});

没关系;但我希望当从 Ember.Select 选择难度时,相应的路径属性将被插入到 img 标签中 有人知道如何得到这个结果吗?

最佳答案

为了实现这一目标,我会设置一些东西。

首先,更新您的 Ember.Select 以包含针对具有新属性的模型的 valueBinding:

{{view Ember.Select id="id_diff" contentBinding="difficulties" optionValuePath="content.id" optionLabelPath="content.title" valueBinding="selectedDificulty"}}

这会将您选择的 View 绑定(bind)到模型对象。这意味着,在 Controller 上,我们现在可以在该字段上包含一个带有 .observes 的新函数:

updateImage : function(){
    this.set('fullPath', this.get('path') + this.get('selectedDificulty'));
}.observes('selectedDificulty');

最后,将图像路径更改为新创建的路径:

<img src="(fullPath)"/>

关于ember.js - 在 Ember.Select 中选择值时更新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21743554/

相关文章:

javascript - Ember.在页面加载时选择空白,但选择了第一个选项

ember.js - 如何在 IIS 中运行 emberJS 应用程序?

javascript - Ember.Select View 提示传递的值

ember.js - Ember i18n 翻译内动态链接

javascript - 在 EmberJS 中,外部 JS 文件应该放在哪里?

javascript - 将 itemController 与每个助手一起使用的 ember.js 无法按预期工作

ember.js - 将 Ember.select 绑定(bind)到从服务器加载的值