我根据select的值过滤列表,但只有在按字符串过滤时才有效。如果我尝试使用id它不会工作。 这是两个证明问题的JsBin:
这个doestn工作:
http://jsbin.com/EveQOke/70/edit
以下是解决方法:
http://jsbin.com/EveQOke/71/edit
首先我将值路径设置为字符串,然后按名称过滤列表。 filterProperty doestn like ids?
一些代码: 的模板
{{view Ember.Select
value=selectedCountry
content=countries
optionValuePath="content.id"
optionLabelPath="content.name"
prompt="Select Country"
}}
JS
filtered: (function() {
console.log(this.get('selectedCountry'));
return this.get('list').filterProperty('country.id', this.get('selectedCountry'));
}).property('selectedCountry')
答案 0 :(得分:1)
是的,它也可以按ID过滤,这里的东西就是这里的ID:
countries : [
{id:'1',name:'Sierre Leone'},
{id:'2',name:'Japan'}
]
是字符串,在这里:
list : [
{id:'1',country:{id:1,name:'Sierre Leone'},nr:'234'},
{id:'2',country:{id:1,name:'Sierre Leone'},nr:'674'},
{id:'3',country:{id:2,name:'Japan'},nr:'934'},
{id:'4',country:{id:2,name:'Japan'},nr:'243'}
]
您将国家/地区的ID设为整数,它们需要具有相同的类型,因此您要么将“'countries”属性更改为具有整数,要么将列表中的国家/地区更改为字符串。