安博.Select optionValuePath不适用于集合id

Ember.Select optionValuePath doesnt work with collection ids

本文关键字:集合 id 适用于 不适用 Select optionValuePath 安博      更新时间:2023-09-26

我根据select的值过滤列表,但它只有在按字符串过滤时才有效。如果我尝试使用id's它不会工作。下面是两个JsBin来演示这个问题:

this does not work:

http://jsbin.com/EveQOke/70/edit

这里是解决方法:

http://jsbin.com/EveQOke/71/edit

首先将值路径设置为字符串,然后按名称过滤列表。filterProperty是否像id ?

一些代码:模板

  {{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')

是的,它也可以按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作为整数,他们需要有相同的类型,所以你要么改变de ' nations '属性为整数或国家列表中的字符串。