Polymer 如何使用铁名单添加联系人搜索,如演示应用程序
我正在尝试实现一个简单的联系人列表。我设置了数据源和该示例中给出的所有内容。现在,如果我想在页面顶部添加一个搜索框或下拉列表,以便用户选择下拉菜单或在搜索框中键入内容,那么如何过滤我的结果。例如:如果用户在搜索框中键入“GRI”,我需要显示名与“GRI”匹配的所有联系人。我该如何实现这一点 假设您这样显示联系人列表:Polymer 如何使用铁名单添加联系人搜索,如演示应用程序,polymer,polymer-1.0,Polymer,Polymer 1.0,我正在尝试实现一个简单的联系人列表。我设置了数据源和该示例中给出的所有内容。现在,如果我想在页面顶部添加一个搜索框或下拉列表,以便用户选择下拉菜单或在搜索框中键入内容,那么如何过滤我的结果。例如:如果用户在搜索框中键入“GRI”,我需要显示名与“GRI”匹配的所有联系人。我该如何实现这一点 假设您这样显示联系人列表: <template is="dom-repeat" items="{{filteredContacts}}" as="contact"> <div>{
<template is="dom-repeat" items="{{filteredContacts}}" as="contact">
<div>{{contact.name}}</div>
</template>
...
...
<script>
filteredContacts: {
type: Array,
value: [],
}
unfilteredContacts: {
type: Array,
value: [{name:"testcontact1"}, {name: "testcontact2"}],
}
//this should be called when input changes on your text input
onFilterTextInputChange : function(){
this.filteredContacts = []; //we empty the array so that old results won't be shown
var filterString = this.$.myFilterTextInput.value(); // we retrieve the text from the text input that we are supposed to filter on
for(var i=0;i<this.unfilteredContacts.length; i++)
{
//Here you make your filtering logics (the example below will only show contacts whose name match exactly what you type in the input field)
var contact = this.unfilteredContacts[i];
if(contact.name == filterString)
this.push("filteredContacts", contact);
}
}
</script>
{{contact.name}
您的列表如下所示:
<template is="dom-repeat" items="{{filteredContacts}}" as="contact">
<div>{{contact.name}}</div>
</template>
...
...
<script>
filteredContacts: {
type: Array,
value: [],
}
unfilteredContacts: {
type: Array,
value: [{name:"testcontact1"}, {name: "testcontact2"}],
}
//this should be called when input changes on your text input
onFilterTextInputChange : function(){
this.filteredContacts = []; //we empty the array so that old results won't be shown
var filterString = this.$.myFilterTextInput.value(); // we retrieve the text from the text input that we are supposed to filter on
for(var i=0;i<this.unfilteredContacts.length; i++)
{
//Here you make your filtering logics (the example below will only show contacts whose name match exactly what you type in the input field)
var contact = this.unfilteredContacts[i];
if(contact.name == filterString)
this.push("filteredContacts", contact);
}
}
</script>
。。。
...
过滤器安装的触点:{
类型:数组,
值:[],
}
未筛选联系人:{
类型:数组,
值:[{name:“testcontact1”},{name:“testcontact2”}],
}
//当文本输入上的输入发生更改时,应调用此函数
onFilterTextInputChange:函数(){
this.filteredContacts=[];//我们清空数组,这样就不会显示旧的结果
var filterString=this.$.myfiltertOutput.value();//我们从文本输入中检索文本,我们应该对其进行筛选
对于(var i=0;i