我有一个由另一个选择下拉列表驱动的选择下拉列表。当Dropdown A被更改时,Dropdown B应该重新呈现自己可能有一组新的选项。
理想的行为是,如果Dropdown B已经设置为一个值并且Dropdown A发生了变化,如果现在重新渲染的Dropdown B中的值也可用,那么该值将被预先选择。
这不会发生在这里。
在模板中:
// Dropdown A
{{ view "select"
content=reportTypes
classNames="form-control"
optionValuePath="content.type"
optionLabelPath="content.name"
value=activeTemplate }}
// Dropdown B
{{ view "select"
content=types
classNames="form-control"
optionValuePath="content.value"
optionLabelPath="content.label"
value=model.type }}
在控制器中:
activeTemplate: Ember.computed('model.template', Ember.ForwardCompatibility.setterGetter({
get: function() {
return this.get('model.template');
},
set: function(key, value) {
this.set('model.template', value);
return value;
}
})),
types: Ember.computed('activeTemplate', function() {
var reportType = this.get('model.reportType');
var types = [];
if (reportType) {
var mapping = CloudUI.ReportUtils.typeToLocalizedKey();
Object.keys(mapping).forEach(function(type) {
if (reportType.hasTimeScope(type)) {
types.push({
label: Ember.localized.localize(mapping[type]),
value: type
});
}
});
}
console.log('model.type:', this.get('model.type'));
// at the moment, types will always be ['Daily', 'Weekly', 'Monthly']
// but we can't expect this in the future
return types;
}),
预期行为:如果下拉列表B的值为“每月”,则当下拉列表A更改且重新生成的下拉列表B中的某个选项为“每月”时,请将下拉列表B设置为“每月”
实际行为:如果下拉列表B的值为“每月”,则当下拉列表A更改时,重新呈现的下拉列表B将设置为第一个选项(在本例中为“每日”) 。但是,this.get('model.type')
仍设为“每月”。
由于this.get('model.type')
仍可正确设置为Dropdown B在Dropdown A更改之前设置的内容,为什么select下拉列表不再轮询模型?
使用Ember v1.10。