Mik*_*uel 0 ember.js ember-data ember-cli
我正在使用一个名为 ember-power-select 的插件。
Github: https: //github.com/cibernox/ember-power-select
用于搜索的文档:https ://ember-power-select.com/docs/the-search
多项选择的文档:https ://ember-power-select.com/docs/multiple-selection/
问题:如何使用name
or进行搜索email
/template.hbs
<PowerSelectMultiple
@searchEnabled={{true}}
@options={{this.authors}}
@selected={{this.author}}
@searchField="email"
@placeholder="Select some names..."
@onChange={{fn (mut this.author)}} as |author|>
{{name}}
</PowerSelectMultiple>
Run Code Online (Sandbox Code Playgroud)
/controller.js
authors = [
{ name: 'Foo', email: 'foo@gmail.com' },
{ name: 'Bar', email: 'bar@gmail.com'},
{ name: 'Baz' email: 'baz@gmai.com'}
]
Run Code Online (Sandbox Code Playgroud)
小智 5
// controller .js
authors = [
{ name: 'Foo', email: 'foo@gmail.com' },
{ name: 'Bar', email: 'bar@gmail.com'},
{ name: 'Baz' email: 'baz@gmai.com'}
]
// add below method you can do something like this
searchMethod(term) {
let result = '';
result = this.authors.filter((item)=>{
if(term == item.name || term == item.email){
return true;
});
return result;
}
Run Code Online (Sandbox Code Playgroud)
/*template.hbs */
<PowerSelectMultiple
@searchEnabled={{true}}
@options={{this.authors}}
@selected={{this.author}}
@search={{this.searchMethod}} /* add @search */
@searchField="email"
@placeholder="Select some names..."
@onChange={{fn (mut this.author)}} as |author|>
{{name}}
</PowerSelectMultiple>
Run Code Online (Sandbox Code Playgroud)
我不确定 searchMethod 的返回类型,您可以检查 power-select lib 并相应地自定义它。
归档时间: |
|
查看次数: |
239 次 |
最近记录: |