fourteen

搜索框功能实现

根据输入框信息传入,对比数据库对应表里的数据进行显示

 

 

const db = wx.cloud.database()
Page({
    data: {
        search: ''
    },
    onLoad: function (options) {

    },
    GetSearchInput: function (e) {
        this.setData({
            search: e.detail.value
        })
    },
    ToSearch: function (e) {
        if (this.data.search == '') {
            wx.showToast({
                icon: 'none'
            })
            return
        }
        db.collection('hotMovie').where({
          hotMovieName: db.RegExp({
                regexp: this.data.search,
                options: 'i',
            }),
        }).get().then(res => {
            if (res.data.length != 0) {
              console.log(res.data)
                this.setData({
                    dianying: res.data
                })
                
            } else {
                wx.showToast({
                    title: '未找到热播电影',
                    icon: 'none'
                })
            }
        })
    },
})
posted on 2022-04-08 21:52  叁柒叭  阅读(140)  评论(0)    收藏  举报