0

次のドロップダウンがあります。

{{view SettingsApp.Select2SelectView
    id="country-id"
    contentBinding=currentCountries
    optionValuePath="content.code"
    optionLabelPath="content.withFlag"
    selectionBinding=selectedCountry
    prompt="Select a country ..."}}

...

{{view SettingsApp.Select2SelectView
    id="city-id"
    contentBinding=currentCities
    selectionBinding=selectedCity
    prompt="Select a city ..."}}

バインドされたプロパティはコントローラーで定義されます。

SettingsApp.ServicesEditController = SettingsApp.BaseEditController.extend(SettingsApp.ServicesMixin, {
    needs            : ['servicesIndex'],
    selectedCountry  : null,
    selectedCity     : null,
    currentCountries : null,
    currentCities    : null,
    init : function () {
        this._super();
    },
    setupController : function (entry) {
        this._super(entry);
        var locator = SettingsApp.locators.getLocator(this.get('content.properties.locator'));
        var countryCode = locator.get('country'), city = locator.get('city');
        this.set('currentCountries', SettingsApp.countries.getCountries());
        this.set('currentCities',    SettingsApp.locators.getCities(countryCode));
        this.set('selectedCountry',  SettingsApp.countries.getCountry(countryCode));
        this.set('selectedCity',     city);
        // Add observers now, once everything is setup
        this.addObserver('selectedCountry', this.selectedCountryChanged);
    },
    selectedCountryChanged: function () {
        var countryCode = this.get('selectedCountry.code');
        var currentCities = SettingsApp.locators.getCities(countryCode);
        var selectedCity = currentCities[0];
        this.set('currentCities', currentCities);
        this.set('selectedCity',  selectedCity);
    },
    ...
});

selectedCountryChanged初期設定は正常に機能していますが、国の選択を変更しても、オブザーバー ( ) が呼び出され、this.set('selectedCity', selectedCity);期待どおりに機能しているにもかかわらず (コンソールのログに表示されるように) 、ドロップダウンの都市の選択が更新されません。オブザーバーのcurrentCities実行後に適切に設定されますが、アクティブな (選択された) 値は正しくありません (変更されません)。

この場合、バインドされたプロパティのプログラムによる更新に関する既知の問題はありますselectionBindingか?

Select2SelectViewは:

SettingsApp.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');
    }

});
4

1 に答える 1

1

select2を削除して(通常のselectに置き換えて)、選択した都市が表示されているかどうかを確認します。その場合、selectionbinding を select2 に伝搬する必要があります。

于 2013-08-07T15:26:52.840 に答える