JS
// pages/selectResult/selectResult.js
const?db?=?wx.cloud.database()
const?$?=?db.command.aggregate
const?_?=?db.command
Page({
data: {
// 定义搜索结果变量,初始化为空数组
postlist: [],
// 定义inputValue,输入框的input值,初始化为空
inputValue: "test"
},
handleInput(e) {
this.setData({
inputValue: e.detail.value,
'postlist': []
})
console.log(e.detail.value)
console.log(this.data.inputValue)
},
// qSearch 发送请求函数(参数为输入框中的值)
// qSearch: function (query) {
// wx.showLoading({
// title: '加载中...',
// })
onShow:?function?()?{
????let?app?=?getApp()
console.log(this.data.inputValue)
??? db.collection('POST').where({
content: db.RegExp({
regexp: this.data.inputValue,//做为关键字进行匹配
options: 'i',//不区分大小写
})
}).get({
??????success:res=>?{
??????console.log("获取信息",res.data)
// console.log(this.data.inputValue)
????????this.setData({
??????????postList:res.data
????????}).reqPostData()
wx.hideLoading();
??????}
????})
??},
reqPostData()?{
????let?postList?=?this.data.postList
????let?len?=?postList.length
????this.setData({
??????vis:true
????})
????wx.cloud.callFunction({
??????name:?'post',
??????data:?{
????????action:?'query',
????????size:?PAGE_SIZE,
????????step:?len,
????????data:?{}
??????},
??????success:?r?=>?{
????????wx.stopPullDownRefresh({
??????????success:?(res)?=>?{},
????????})
????????console.log(r.result.data[0])
????????this.setData({
??????????vis:false,
??????????postList:?postList.concat(r.result.data)
????????})
??????},
??????fail:?r?=>?{
????????console.log(r)
??????},
??????complete:res=>{
????????this.setData({
??????????vis:false
????????})
??????}
????})
??},?
// 成功获取数据后,把加载中的提示关掉
// }
// });
// },
handleCanle: function () {
this.setData({
searchResult: [],
inputValue: ""
})
wx.hideLoading();// 成功获取数据后,把加载中的提示关掉
}
})
|