收藏
回答

为何我请求不到数据库中的数据?

var utils = require('../../utils/util.js');
let app = getApp();
// 获取云数据库引用
const db = wx.cloud.database();
const allbookmsg = db.collection('booklist');
let bookmsg = null;
let password = null;


//index.js
//获取应用实例
var screenNum = 3;
// var app = getApp()
Page({
    data: {
        cateisShowfalse,
        activeNum1,
        loadingtrue,
        bookObj:null,
    },
    inputBook:function(event){
         bookmsg=event.detail.value;
        console.log(bookmsg)


    },


    //事件处理函数
    bindViewTapfunction () {
        wx.navigateTo({
            url'../logs/logs'
        })
    },


    onPullDownRefreshfunction () {
        //监听页面刷新
        this.onLoad()
        wx.stopPullDownRefresh()
    },


    onLoadfunction () {
        console.log(bookmsg);
        var that = this;
        utils.getUserData();
        //图书列表数据获取
        // wx.request({
        //     url: 'http://' + app.globalData.apiUrl + '/bookshare?m=home&c=Api&a=bookList',
        //     method: "GET",
        //     success: function (res) {
        //         that.setData({
        //             bookObj: res.data,
        //             loading:false
        //         })
        //     },
        //     fail: function () {
        //         wx.showToast({
        //             title: '获取数据失败,请稍后重试!',
        //             icon: 'false',
        //             duration: 2000
        //         })
        //     }
        // })
        
    },


    onShowfunction () {
        this.onLoad() 
        console.log(bookmsg)
    },
    
    changeTabfunction (event{
        //切换筛选tab
        var num = event.target.dataset.id;
        this.setData({
            activeNum: num
        })
    },
    searching:function(){
        let that = this;
        allbookmsg.get({
            success(res) => {
                console.log(res);
            }
        })
    },


    screenISBNfunction () {
        console.log("搜索功能执行");
        wx.getSetting({
            success(res) {
                console.log(res);
                if (res.authSetting['scope.userInfo']) {
                    //已授权 扫描ISBN
                    wx.scanCode({
                        success(res) => {
                            if (res.errMsg == "scanCode:ok") {
                                //扫描成功
                                if (res.scanType == "EAN_13") {
                                    //条形码
                                    var isbnCode = res.result;
                                    wx.navigateTo({
                                        url'../share/share?isbn=' + isbnCode,
                                    })
                                } else {
                                    wx.showToast({
                                        title'条形码有误!',
                                    })
                                }
                            } else {
                                wx.showToast({
                                    title'获取数据失败,请稍后重试!',
                                })
                            }
                        }
                    })
                }else{
                    utils.checkSettingStatu();
                }
            }
        })
        
    },


    detailfunction (event{
        var bookId = event.currentTarget.dataset.bookid;
        var canShareId = event.currentTarget.dataset.canshareid;
        var book_type = event.currentTarget.dataset.type;//type 为1时自营点 为0时C2C
        //打开详情页
        wx.navigateTo({
            url'../detail/detail?bookId=' + bookId + "&canShareId=" + canShareId + "&book_type=" + book_type,
        })
    },
    
    togglePtypefunction () {
        //显示分类
        this.setData({
            cateisShow: !this.data.cateisShow
        })
    },
})


searching:function(){
        let that = this;
        allbookmsg.get({
            success(res) => {
                console.log(res);
            }
  c此处我请求到的res信息没有任何数组 

此处的booklist是我存进去的数据,但是打印出来的res却没有,这是为什么?

回答关注问题邀请回答
收藏

2 个回答

  • Admin ²º²³
    Admin ²º²³
    2020-05-20

    数据库权限设置了吗?

    所有人可读?

    2020-05-20
    有用 1
    回复 2
    • Hall of fame
      Hall of fame
      2020-05-20
      谢谢,大佬,果然可以读出来了
      2020-05-20
      回复
    • Admin ²º²³
      Admin ²º²³
      2020-05-20回复Hall of fame
      不客气,这是我应该做的~能帮到你是我的荣幸!希望咱们能继续在社区保持交流。
      2020-05-20
      回复
  • Hall of fame
    Hall of fame
    2020-05-20

    这是我请求到的res信息内容

    2020-05-20
    有用
    回复
登录 后发表内容
问题标签