wxml:
<input placeholder="取前几个" bindinput="inputRecordNumber"></input>
<input placeholder="score不小于的值" bindinput="inputMinSocre"></input>
<button type="primary" bindtap="getDataFromBuyerBasics">获取数据</button>
<view wx:for="{{dataArray}}" wx:key="index">{{index+1}}-{{item.buyerName}}-{{item.score}}</view>
wxss:
page{
padding: 10rpx;
box-sizing: border-box;
}
input{
border: 1px solid #000;
}
view{
border: 1px solid #000;
}
js:
// 连接微信云数据库
const db = wx.cloud.database()
const _ = db.command
var recordNumber
var minScore
Page({
data: {
"dataArray":""
},
// 获取记录的个数
inputRecordNumber(res){
console.log(res.detail.value)
recordNumber = Number(res.detail.value)
},
// 获取score的最小值
inputMinSocre(res){
console.log(res.detail.value)
minScore = Number(res.detail.value)
},
// 获取buyerBasics的数据
getDataFromBuyerBasics(){
db.collection("buyerBasics")
.where({
"score": _.gte(minScore)
})
.limit(recordNumber)
.orderBy("score","desc")
.get()
.then(res=>{
console.log(res.data)
this.setData({
"dataArray":res.data
})
})
},
onLoad: function (options) {
}
})
前端效果图:
后端运行结果: