0

機能Ember.Selectを有効にするために、このラッパーを使用しています。Select2

App.Select2SelectView = Ember.Select.extend({
    prompt: 'Please select...',
    classNames: ['input-xlarge'],

    didInsertElement: function() {
        Ember.run.scheduleOnce('afterRender', this, 'processChildElements');
    },

    processChildElements: function() {
        this.$().select2({
            // do here any configuration of the
            // select2 component
            escapeMarkup: function (m) { return m; } // we do not want to escape markup since we are displaying html in results
        });
    },

    willDestroyElement: function () {
        this.$().select2('destroy');
    }

});

ドロップダウンを非表示にする必要がある場合があり、次のようにします。

{{#if cityVisible}}
    <div class="control-group">
        <label class="control-label">City</label>
        <div class="controls">
            {{view SettingsApp.Select2SelectView
                id="city-id"
                contentBinding="currentCities"
                optionValuePath="content.city"
                optionLabelPath="content.city"
                selectionBinding="controller.selectedCity"
                prompt="Select a city"}}
            <i class="help-block">Select the city for your geographical number</i>
        </div>
    </div>
{{/if}}

しかし、ドロップダウンが表示されないときはいつでも、次のエラーが発生します。

Uncaught TypeError: Cannot call method 'select2' of undefined 

要素が挿入されたと思いますが、 (バインドされたプロパティ)Emberから削除されたので、それを見つけることができませんか?DOMcityVisiblejQuery

そのエラー メッセージを回避するにはどうすればよいですか? ビューを表示/非表示にしたくありません。全体を制御control-group下に置きたいです。cityVisible

4

1 に答える 1