搜索功能
先说一下需求 点击搜索按钮 根据我输入的内容进行搜索
我的表格里有两列 一个是name 一个是age
可以搜索 名字(小王) 年龄(23)
这里只写了js html的话就写个input和button就ok
search () {
let text = this.text
this.dataOne= !text ? this.dataTwo : this.dataTwo.filter(item =>item.age.includes(text) || item.name.includes(text))
this.baseClassifies = []
}
说明:
- search->搜索按钮
- text->搜索的字段
- dataOne->被搜索的数据
- dataTwo->这个也是被搜索的数据 因为filter需要返回到新数组
扩展知识: - includes()
arr.includes(‘小王’) arr数组里包含小王
es6语法,在数组中是否包含内容