在搜索框中随意输入一个值后,点击搜索框就跳转,想实现输入关键词后在跳转怎么做?
//index.js
//获取应用实例
const app = getApp()
let searchKey = ''
let api = require('../../config/api');
const db = wx.cloud.database()
const data = require('../../config/data.js')
Page({
data: {
height:app.globalData.height*2+90,
swipers:['swiper1','swiper2','swiper3'],
active:0,
plist:[],
serverPath:api.ApiRootUrl,
page:1,
result:{},
good:{}
},
//事件处理函数
bindViewTap: function() {
wx.navigateTo({
url: '../logs/logs'
})
},
onLoad: function () {
console.log(data.tuijian)
this.setData({
plist:data.tuijian
})
},
tapName(e){
console.log(e)
wx.navigateTo({
url: '/pages/index4/index4',
})
},
onChange(event) {
// event.detail 的值为当前选中项的索引
console.log(event.detail)
this.setData({ active: event.detail });
switch(event.detail){
case 0:
wx.navigateTo({
url: '/pages/index/index',
})
break;
case 1:
wx.navigateTo({
url: '/pages/mine/mine',
})
break;
}
},
getSearch(event) {
// event.detail 的值为当前选中项的索引
console.log(event.detail.value)
searchKey = event.detail.value
},
goSearch(){
console.log('触发了搜索',searchKey)
if(searchKey&& searchKey.length > 0){
// wx.navigateTo({
// url: '/pages/index6/index6?searchKey=' + searchKey,
// })
const db = wx.cloud.database({
})
db.collection("mianliao").where({ //collectionName 表示欲模糊查询数据所在collection的名
name:db.RegExp({ //columnName表示欲模糊查询数据所在列的名
regexp:searchKey,
options:"i",
})
})
// }else if(searchKey == none) {
// wx.showToast({
// icon:"none",
// title: '搜索词不存在',
// })
}
else{
wx.showToast({
icon:"none",
title: '搜索词为空',
})
}
wx.navigateTo({
// // url: '/pages/index5/index5?id='+e.currentTarget.dataset.id,
// // url: '/pages/index5/index5?id='+e.currentTarget.dataset.id,
url: '/pages/index6/index6?searchKey=' + searchKey,
})
},
reachBottom(){
console.log('到达底部')
this.page++;
wx.request({
url:"http://localhost:9529/",
// url: api.GoodsList,
success:(res)=>{
let plist = res.data.productlist;
plist.forEach((item,i)=>{
item.imgs = JSON.parse(item.imgs)
})
plist = this.data.plist.concat(plist)
console.log(plist)
this.setData({
plist:plist
})
}
})
},
goBack(){
wx.navigateBack()
}
})
没看明白,可以详细点吗