2

使用 Ember.Select 视图,例如:

{{view Ember.Select viewName="select"
    contentBinding="view.noseNames"
    prompt="Add a Nose:"
    selectionBinding="view.noseToAdd" 
}}

当用户选择要添加的鼻子时,我想将 Ember.Select 重置回提示。我怎么做?我试过 set('noseToAdd' null),但它只是将 Select 设置为一个空白项。

显示问题的完整 JSFiddle:

http://jsfiddle.net/tyH8L/4/


车把

<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')
});​
4

1 回答 1

2

你试过设置selectionnull

更新:

这是一个已修复的错误:https ://github.com/emberjs/ember.js/commit/7a2a14b81aa7adf46c76c272f93c8aff31749582

于 2012-06-02T23:38:44.540 回答