我在使用Ember.Select时遇到了一个问题,当“内容”绑定发生变化时,“值”绑定不会保持同步(返回到第一个值)。
这是一个JSBin:http://emberjs.jsbin.com/kafod/1
基本上,更改类别会更改Ember.Select视图的可用值,然后它会恢复为第一个可用值。
有人能帮上忙吗?
发布于 2014-02-16 02:08:18
Ember.Select组件需要选择一个值,这样当您切换出类别时,sort字段就会被覆盖。一个简单的解决方案是有两个排序字段,sortAccomodations和sortEvents,以及两个Ember.Selects,您可以根据所选的类别在模板中进行切换。
有关工作示例,请参阅http://emberjs.jsbin.com/kafod/3/。
{{#if categoryIsAccommodations}}
<br />Sort by {{view Ember.Select content=sortOptions
optionValuePath="content.key"
optionLabelPath="content.text"
value=sortAccomodations}}
{{/if}}
{{#if categoryIsEvents}}
<br />Sort by {{view Ember.Select content=sortOptions
optionValuePath="content.key"
optionLabelPath="content.text"
value=sortEvents}}
{{/if}}具有一个“sort”值的解决方案:
{{view Ember.Select content=sortOptions
optionValuePath="content.key"
optionLabelPath="content.text"
value=sort}}控制器:
saveSorts: (->
this.set('sortAccommodations', this.get('sort')) if this.get('category') is 'accommodations'
this.set('sortEvents', this.get('sort')) if this.get('category') is 'events'
).observes('sort')
categoryDidChange: (->
this.set('sort', this.get('sortAccommodations')) if this.get('category') is 'accommodations'
this.set('sort', this.get('sortEvents')) if this.get('category') is 'events'
).observes('category')http://emberjs.jsbin.com/kafod/5/
https://stackoverflow.com/questions/21799090
复制相似问题