2

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

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

Select 填充了来自服务器的值;在控制器中:

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 标签中有人知道如何得到这个结果吗?

4

1 回答 1

2

为了做到这一点,我会设置一些东西。

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

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

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

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

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

<img src="(fullPath)"/>
于 2014-02-13T02:25:13.573 回答