小程序开发之从数据库获取数据显示在页面

由于才开始学习,只是做个案例,格式什么的就随便写了下

效果如下:

testQuery.wxml

<view class="guide">
    <text class="headline"></text>
    <text class="p"></text>
    <text class="p"></text>
    <text class="p"> 点击查询按钮</text>
    <button size="mini" type="default" bindtap="onQuery">查询记录</button>
    <view class="table">
        <view class="tr">
            <view class="th" style="width:10%">姓名</view>
            <view class="th" style="width:10%">性别</view>
            <view class="th" style="width:30%">身份证</view>
            <view class="th" style="width:10%">身高</view>
            <view class="th" style="width:30%">出生地</view>
        </view>
    </view>
<view class="tr" wx:for="{{ne}}">
    <view class="td" style="width:5%">{{item.userName}}</view>
    <view class="td" style="width:10%">{{item.sex}}</view>
    <view class="td" style="width:23%">{{item.idcard}}</view>
    <view class="td" style="width:10%">{{item.hight}}</view>
    <view class="td" style="width:30%">{{item.birthplace}}</view>
</view>
  </view>

testQuery.js

Page({

    /**
     * 页面的初始数据
     */
    data: {
        ne:[],

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },
    

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },
    onQuery: function() {
        const db = wx.cloud.database()
        // 查询当前用户所有的 counters
        db.collection('test').where({
          _openid: this.data.openid
        }).get({
          success: res => {
            this.setData({
              queryResult: JSON.stringify(res.data, null, 2),
              ne: res.data
            })
            console.log('[数据库] [查询记录] 成功: ', res)
          },
          fail: err => {
            wx.showToast({
              icon: 'none',
              title: '查询记录失败'
            })
            console.error('[数据库] [查询记录] 失败:', err)
          }
        })
      },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})

testQuery.wxss

.table{
    border-right: 0;
    border-bottom: 0;
    /* width: 70%; */
    border: 1px solid #dadada
    }
    .tr{
       display: flex;
      justify-content: space-between
    }
    
    .td {
    padding: 10px;
    border-bottom: 1px solid #dadada;
    border-right: 1px solid #dadada;
    text-align: center;
    font-size-adjust: 0.1 ;
    width:100%;
    text-overflow:ellipsis;
    word-break: keep-all;word-wrap: break-word;white-space: pre-line;
    
    /* overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis; */
  
      }
    
    .th {
    font-weight: 100;
     background-color: #13921a;  
     text-align: center;
    
    }

 

  • 3
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

心寒丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值