【问题标题】:Ember Select set default value when the content changeEmber Select 内容更改时设置默认值
【发布时间】:2014-05-28 15:26:18
【问题描述】:

我有 2 个选择,第二个(多个)取决于第一个(简单)

第一个:

{{view Ember.Select content=siteGroups selection=selectedSiteGroup}}

第二个:

 {{view Ember.Select content=sites optionLabelPath="content.name"  value=selectedSite multiple=true selection=selectedSiteDefault}}

所以,selectedSiteGoup (select 2) 改变了第一个的内容。

我已经设置了第二个的默认值:

selectedSiteDefault: function(){
  return this.get('sites.firstObject');
}.property('selectedSiteGroup')

它可以工作,但是当内容发生变化时(由于第一次选择)它不会将任何值设置为默认值。

我该如何解决?

【问题讨论】:

    标签: ember.js


    【解决方案1】:

    Here is a demo 带有 2 个选择框。第二个选择框的内容是基于第一个选择框的。

    第二个选择框的默认值为最后一项。

    var continents = ['America', 'Europe', 'Asia'];
    var countries = {
      'America': ['Texas','New York'],
      'Europe': ['Estonia','Germany'],
      'Asia': ['India','China']
    };
    
    App = Ember.Application.create();
    
    App.Router.map(function() {
      // put your routes here
    });
    
    App.IndexRoute = Ember.Route.extend({
      model: function() {
        return {
          'continents': continents,
          'countries': countries
        };
      }
    });
    
    App.IndexController = Em.ObjectController.extend({
      continent: 'Asia',
      country: function() {
        return this.get('countries.'+this.get('continent'));
      }.property('continent'),
      countrySel: function() {
        return this.get('country.lastObject');
      }.property('country.[]')
    });
    
    {{view Ember.Select content=content.continents valueBinding="continent"}}
    {{view Ember.Select content=country selection=countrySel}}
    

    【讨论】:

    • 谢谢!但是你如何存储在第二个选择中选择的值?价值=?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-15
    相关资源
    最近更新 更多