簡體   English   中英

無法使用Ember篩選模型。在Ember.js中選擇

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

用例是我試圖使用Ember篩選模型。選擇,每當用戶單擊按鈕時,都會基於'Designation'屬性來篩選模型。

這是我的灰燼。選擇:

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

這就是我在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);
        }
    }
});

這是完整的JSBin, http: //jsbin.com/iPUxuJU/2/edit

我在這里可能會缺少什么?

您在選擇綁定中缺少某些內容

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

在控制器邏輯中:

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);
    }
}

});

這是工作的jsbin

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM