我想从控制器重置(打印)一个选择。选择更改为提示值,但仅当我手动重置时才会显示整个列表。
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')
});