Emberjs以编程方式重置select

时间:2014-05-27 21:06:30

标签: javascript ember.js

我想从控制器重置(打印)一个选择。选择更改为提示值,但仅当我手动重置时才会显示整个列表。

App.IndexController = Ember.Controller.extend(Ember.Validations.Mixin, {
  selectedCountry: null,
  selectedNumber: null,
  actions: {
    submit: function() {
      alert('Saved!');
      console.log(this.name);
      console.log(this.country_list);
    },
    resetForm:function(){
      console.log('try to reset form');
      this.set('selectedCountry',null);
      this.set('selectedNumber',null);
    }    
  },

  countries : [
    {id:'1',name:'Sierre Leone'},
    {id:'2',name:'Japan'}

  ],
    numbers : [
    {id:'1',name:'234'},
    {id:'2',name:'674'}

  ],
    list : [
    {id:'1',name:'Sierre Leone',nr:'234'},
    {id:'2',name:'Japan',nr:'674'},
    {id:'3',name:'Sierre Leone',nr:'934'},
    {id:'4',name:'Japan',nr:'243'}
  ],

  filtered: (function() {
    var temp = this.get('list');
    if (this.get('selectedCountry') !== null) 
      temp = temp.filterProperty('name', this.get('selectedCountry'));
    if (this.get('selectedNumber') !== null) 
      temp = temp.filterProperty('nr', this.get('selectedNumber'));

    return temp;
  }).property('selectedCountry','selectedNumber')
});

这是JsBin http://emberjs.jsbin.com/EveQOke/88/edit

0 个答案:

没有答案