在数组中查找满足条件进行筛选,可以用wxs文件进行方法封装,通过bindinput事件将value储存,返回数组中是否有包含当前value的对象,通过indexOf判断,如果返回空则表示存在当前对象,则不进行任何操作,如果返回一个对象,则不包含当前对象,设置style的display设置为none进行隐藏。
wxs文件
function searchInp(item, str) {
return item.name.indexOf(str) !== -1 || item.age.indexOf(str) !== -1 || "";
}
module.exports = {
searchInp: searchInp
};
wxml文件
<wxs src="./index.wxs" module="fun"/>
// 判断当前对象是否存在
<view wx:for='{{list}}' style="{{fun.searchInp(item, searchVal) ? '' : 'display: none'}}"></view>