数据库取值问题?
发布于 6 年前 作者 lyu 1431 次浏览 来自 问答

各位前辈,本人小白,

最近刚接触先小程序要做一个账本类小程序,用到了云数据库,取值 来制作折线图为此打算用termarr数组存储数据库的数据 在打印台能显示数据库但是存不到数组里 查了一下数据库返回promise类型 到底该怎么写求救大神

// pages/indecv2/indecv2.js

Page({

  /**

   * 页面的初始数据

   */

  data: {

 

    re:"",

 

     termarr : [   //待保存数据数组

      {

        countdetail: “生活”,

        countnum: “669”,

        day: “02”,

        due: “9/53/42”,

        month: 12,

        year: 2019

      },

    ]

  },

  search2: function (e)   {      //添加按钮查看数组

      console.log(this.data. termarr);

  },

  search: function (e){    //数据库取值并存入

    const db = wx.cloud.database();

   db.collection(‘shouru’).where({

      month:12

    })

 

      .get({

        success: function (res) {

 

          console.log( res.data)

          that.setData({

            termarr: res.data

          })

          }

      })

  },

  /**

   * 生命周期函数–监听页面加载

   */

  onLoad: function (options) {

    let that = this

  },

  /**

   * 生命周期函数–监听页面初次渲染完成

   */

  onReady: function () {

  },

  /**

   * 生命周期函数–监听页面显示

   */

  onShow: function () {

  },

  /**

   * 生命周期函数–监听页面隐藏

   */

  onHide: function () {

  },

  /**

   * 生命周期函数–监听页面卸载

   */

  onUnload: function () {

  },

  /**

   * 页面相关事件处理函数–监听用户下拉动作

   */

  onPullDownRefresh: function () {

  },

  /**

   * 页面上拉触底事件的处理函数

   */

  onReachBottom: function () {

  },

  /**

   * 用户点击右上角分享

   */

  onShareAppMessage: function () {

  }

})

  },

  /**

   * 页面上拉触底事件的处理函数

   */

  onReachBottom: function () {

  },

  /**

   * 用户点击右上角分享

   */

  onShareAppMessage: function () {

  }

})

1 回复

const db = wx.cloud.database();

db.collection(‘shouru’).where({

month: 12

}).get().then(res => {

console.log(res.data)

that.setData({

termarr: res.data

})

})

回到顶部