首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用iron-list添加搜索联系人,如演示应用程序

如何使用iron-list添加搜索联系人,如演示应用程序
EN

Stack Overflow用户
提问于 2015-11-01 22:28:03
回答 1查看 383关注 0票数 0

我正在尝试实现一个简单的联系人列表的one shown here。我按照该示例中给出的方式设置了数据源和所有内容。现在,如果我想在页面顶部添加搜索框或下拉框,以便用户选择下拉菜单或在搜索框中键入内容,我如何过滤我的结果。例如:如果用户在搜索框中键入"GRI“,我需要显示名字与"GRI”匹配的所有联系人。你知道我该如何实现它吗?

EN

回答 1

Stack Overflow用户

发布于 2015-11-02 01:54:02

假设您按如下方式显示联系人列表:

代码语言:javascript
复制
<template is="dom-repeat" items="{{filteredContacts}}" as="contact">
   <div>{{contact.name}}</div>
</template>

你的列表看起来像这样:

代码语言:javascript
复制
...
...
<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>

注意,上面的代码可能不能仅用于复制-粘贴。可能有一些语法错误,但您应该了解如何继续进行。:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33463219

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档