對數組的基本模糊查詢
定義數組
mallList: [ { id: 1, img: 'https://tse2-mm.cn.bing.net/th/id/OIP.B5xAajd2dWNwJn2Q7IY-IQHaEK', title: '霍尼韋爾H910Plus系列KN95防霧系列KN95防霧系列KN95防霧霾口罩', money: 105, num: 550 }, { id: 2, img: 'https://tse2-mm.cn.bing.net/th/id/OIP.B5xAajd2dWNwJn2Q7IY-IQHaEK', title: '家用洗臉毛巾', money: 110, num: 1000 }, { id: 3, img: 'https://tse2-mm.cn.bing.net/th/id/OIP.B5xAajd2dWNwJn2Q7IY-IQHaEK', title: '小霸王牌多功能電飯鍋', money: 15, num: 700 }, { id: 4, img: 'https://tse2-mm.cn.bing.net/th/id/OIP.B5xAajd2dWNwJn2Q7IY-IQHaEK', title: '自助飲食', money: 99, num: 680 } ],
創建方法,並進行模糊查詢
onDropItem() { var mallList = this.data.mallList mallList = mallList.filter(function (t) { return t.title.search('飲食') > -1 //search()或者indexOf() }) this.setData({ mallList: mallList }) },