使用 Ember.Select 视图,例如:
{{view Ember.Select viewName="select"
contentBinding="view.noseNames"
prompt="Add a Nose:"
selectionBinding="view.noseToAdd"
}}
当用户选择要添加的鼻子时,我想将 Ember.Select 重置回提示。我怎么做?我试过 set('noseToAdd' null),但它只是将 Select 设置为一个空白项。
显示问题的完整 JSFiddle:
车把:
<script type="text/x-handlebars">
{{#view App.PickANose}}
{{view Ember.Select
contentBinding="view.noseNames"
prompt="Add a Nose:"
selectionBinding="view.noseToAdd"
}}
{{/view}}
Picked Noses:
{{#each App.noses}}{{this}}, {{/each}}
</script>
</p>
JavaScript:
App = Ember.Application.create({
noses: []
});
App.PickANose = Ember.View.extend({
noseNames: ['broken', 'roman', 'hawkish', 'aquiline'],
noseToAdd: null,
aNoseWasPicked: function () {
if (Ember.none(this.get('noseToAdd'))) return;
var noseToAdd = this.get('noseToAdd');
App.get('noses').pushObject(noseToAdd);
// HERE IS THE QUESTION:
// How do I return the select back to "Add a nose:" ?
// The following doesn't work in the latest EmberJS
this.set('noseToAdd', null);
}.observes('noseToAdd')
});