简体   繁体   中英

Not able to filter the model using the Ember.Select in Ember.js

The use case is I am trying to filter the model using the Ember.Select, whenever the user clicks the button, the model gets filtered on the basis of the 'Designation' property.

Here's my Ember.Select:

{{view Ember.Select
       contentBinding="designations"
       optionValuePath="content.id"
       optionLabelPath="content.designation"
       selectionBinding="roles.selectedDesignation"}}
<button {{action 'filter'}}>Filter</button>

And Here's what I am doing in App.js,

App.TwodController = Ember.Controller.extend({
    filteredContent : Ember.computed.oneWay("content"),
    selectedDesignation : null,
    designations : [{
        designation : "Design",
        id : 1
    }, {
        designation : "Writer",
        id : 2
    }],
    actions : {
        filter : function() {
            var designation = this.get('roles.selectedDesignation');
            var filtered = this.get('content').filterProperty('designation', designation);
            this.set("filteredContent", filtered);
        }
    }
});

Here's the full JSBin, http://jsbin.com/iPUxuJU/2/edit

What I might be missing here?

You are missing something in selection binding

{{view Ember.Select
   contentBinding="designations"
   optionValuePath="content.id"
   optionLabelPath="content.designation"
   selectionBinding="selectedDesignation"}}
<button {{action 'filter'}}>Filter</button>

In controller logic:

App.TwodController = Ember.Controller.extend({
filteredContent : Ember.computed.oneWay("content"),
selectedDesignation : null,
designations : [{
    designation : "Design",
    id : 1
}, {
    designation : "Writer",
    id : 2
}],
actions : {
    filter : function() {
        var designation = this.get('selectedDesignation.designation');
        var filtered = this.get('content').filterProperty('designation', designation);
        this.set("filteredContent", filtered);
    }
}

});

Here is the working jsbin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM