简体   繁体   English

无法使用Ember筛选模型。在Ember.js中选择

[英]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. 用例是我试图使用Ember筛选模型。选择,每当用户单击按钮时,都会基于'Designation'属性来筛选模型。

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.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 这是完整的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 这是工作的jsbin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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