新手做了一个小程序,想实现搜索某个词,如果数据库name字段中包含,这返回显示在搜索结果也中,代码如下:
result,wxml
<view class="weui-search-bar">
<view class="weui-search-bar__form">
<view class="weui-search-bar__box">
<icon class="weui-icon-search_in-box" type="search" size="14"></icon>
<input type="text" class="weui-search-bar__input" disabled='true' placeholder="搜索入口" bindtap="wxSearchTab"/>
</view>
</view>
</view>
<view>我们为你搜索到关于{{searchValue}}的内容,结果如下:</view>
<view class="service-list">
<navigator class="service-item" wx:for="{{data}}" wx:key="{{item.id}}" url="../proInfo/index?id={{item.id}}">
<view class="service-img">
<image src="{{item.pic}}" mode="aspectFill"></image>
</view>
<view class="service-text">
<view class="service-tite">{{item.name}}</view>
<text class="service-city">价格:{{item.price}}</text>
</view>
</navigator>
</view>
result.js
//index.js
Page({
data: {
searchValue:{},
data:[],
},
// 搜索页面跳回
onLoad: function (options) {
if (options && options.searchValue) {
this.setData({
searchValue: options.searchValue
});
const db = wx.cloud.database()
const _ = db.command
db.collection('searchlist').where({
name: _.in(['searchValue'])
}).get({
success: res => {
this.setData({
data: res.data
})
console.log('[数据库] [查询记录] 成功: ', res)
},
fail: err => {
wx.showToast({
icon: 'none',
title: '查询记录失败'
})
console.error('[数据库] [查询记录] 失败:', err)
}
})
}
},
// 搜索入口
wxSearchTab: function () {
wx.redirectTo({
url: '../search/search'
})
}
})
页面显示结果如图:
数据库:
console返回结果:
[数据库] [查询记录] 成功: {data: Array(0), errMsg: "collection.get:ok"}
请教是什么情况呢?为什么数据库查询成功而没有返回数据呢?