新手,请教问题。其中js代码中this.data.inputidcard换成具体的值,能查询集合的数据。请各位大侠看看是什么问题。
js代码:
const app = getApp();
// 获取云数据库引用
const db = wx.cloud.database();
const admin = db.collection('chengji');
Page({
data: {
//定义一个数据,主要是放集合结果的
ne: [],
inputidcard: ''
},
onLoad: function (options) {
var that = this;
// 调用login云函数获取openid
const db = wx.cloud.database({
//这个是环境ID不是环境名称
env: 'XXXXXX'
})
},
queryData: function () {
var that = this;
// 根据记录ID搜索数据集
admin.where({ idcard:'this.data.inputidcard'}).get({
//如果查询成功的话
success: res => {
//这一步很重要,给ne赋值,没有这一步的话,前台就不会显示值
that.setData({
ne: res.data
})
},
fail: function (res) {
wx.showModal({
title: '错误',
content: '没有找到记录',
showCancel: false
})
}
})
},
inputIdcard: function (event) {
this.setData({
inputidcard:event.detail.value
})
}
})
wxml代码:
<view class="main-body">
<view class="option" >
<view class='wrapper'>
<view class='top'>
<image mode='widthFix' src='/images/bottom12313.png'></image>
<view>
<i-input value='{{inputidcard}}' bind:change='inputIdcard' maxlength="18" title="身份证号" autofocus placeholder="请输入身份证号码" />
<i-button bindtap='queryData' type="primary">查 询 成 绩</i-button>
</view>
</view>
<view class="hs20"></view>
<view>
<view class="list-title-left">姓名:</view>
<view class="list-title-right" wx:for='{{ne}}' wx:key='key'>
<text space='nbsp'>{{item.name}}</text>
</view>
<view class="clear"></view>
</view>
<view class="hs20"></view>
<view>
<view class="list-title-left">班级:</view>
<view class="list-title-right" wx:for='{{ne}}' wx:key='key'>
<text space='nbsp'>{{item.class}}</text>
</view>
<view class="clear"></view>
</view>
<view class="hs20"></view>
<view>
<view class="list-title-left">时间:</view>
<view class="list-title-right" wx:for='{{ne}}' wx:key='key'>
<text space='nbsp'>{{item.year}}</text>
</view>
<view class="clear"></view>
</view>
<view class="hs20"></view>
<view>
<view class="list-title-left">色彩:</view>
<view class="list-title-right" wx:for='{{ne}}' wx:key='key'>
<text space='nbsp'>{{item.sc}}</text>
</view>
<view class="clear"></view>
</view>
<view class="hs20"></view>
<view>
<view class="list-title-left">素描:</view>
<view class="list-title-right" wx:for='{{ne}}' wx:key='key'>
<text space='nbsp'>{{item.sm}}</text>
</view>
<view class="clear"></view>
</view>
<view class="hs20"></view>
<view>
<view class="list-title-left">速写:</view>
<view class="list-title-right" wx:for='{{ne}}' wx:key='key'>
<text space='nbsp'>{{item.sx}}</text>
</view>
<view class="clear"></view>
</view>
<view class='footer'>XXX·Art.Exam</view>
</view>
</view>
</view>
相似问题