1
我遇到了Ember.Select问题,其中“值”绑定不保持同步(回到第一个值),当“内容”绑定更改。Ember.Select“值”不保持与绑定同步
这里是一个JSBin:http://emberjs.jsbin.com/kafod/1
基本上,改变类别改变的可用值的Ember.Select视图,并且它返回到第一个可用的值。
任何人都可以帮忙吗?
我遇到了Ember.Select问题,其中“值”绑定不保持同步(回到第一个值),当“内容”绑定更改。Ember.Select“值”不保持与绑定同步
这里是一个JSBin:http://emberjs.jsbin.com/kafod/1
基本上,改变类别改变的可用值的Ember.Select视图,并且它返回到第一个可用的值。
任何人都可以帮忙吗?
那么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}}
一个解决方案 '排序' 值:
{{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')
这不是我能够用两个 “排序” 值,因为它包含在查询字符串中。你能想到另一种解决方法吗? – elsurudo
当然,您可以在切换类别时“保存”相应的排序值,并在切回时“重新加载”它们。看到http://emberjs.jsbin.com/kafod/5/ – chopper
这绝对是到达那里,但仍然有一个我找不到的错误。首次加载JSBin时,请执行以下操作:1.按“名称升序”排序2.将类别更改为“事件”3.将类别更改回“住宿”。页面现在处于不一致的状态,其中Ember.Select的值与“排序”不匹配。嗯 – elsurudo