收藏
回答

小程序端获取云数据库数据get的success无法调用wx.showModal?

这是我的代码

```

load: function (shareName, shareKey){

    wx.showLoading({

    title: '下载中',

    })

    wx.cloud.init();

    const db = wx.cloud.database()

    db.collection('shareData').where({

    shareName: shareName,

    shareKey: shareKey

    }).get({

        success: function (res) {

            console.log(res.data);

            wx.hideLoading();

            var data = res.data[0];

            var nickName = data[0].nickName;

            var e = data[0].source;

            var repotPath = data[0].reportPath;

            var index = data[0].index;   //程序运行到这里下面的没有执行

                wx.showModal({

                title: '已下载',

                content: '是否跳转到页面',

                success: function (res) {

                    if (res.confirm) {

                    wx.navigateTo({

                    url: repotPath,

                   success: function (res) { },

            });

        } else if (res.cancel) {

            console.log('用户点击取消')

}

}

});

}

});

},

```

回调函数用起来感觉很多坑

这个wx.showModal 就可以正常调用

addData: function (shareName, shareKey){

wx.showLoading({

title: '上传中',

})

wx.cloud.init();

const db = wx.cloud.database();

var userInfo = wx.getStorageSync('userInfo');

var openid = wx.getStorageSync('open_Id');

db.collection('shareData').add({

data: {

myid: openid + this.data.url,

nickName: userInfo.nickName,

shareName: shareName,

shareKey: shareKey,

userInfo: userInfo,

source: this.data.e,

reportPath: this.data.url,

index:this.data.index

},

success: function (res) {

wx.hideLoading();

wx.setStorageSync('isAdd', true);

wx.showModal({

title: '上传成功',

content: '---------------有效时间10分钟-------------- Name:' + shareName + "----      Key: " + shareKey,

success:function(){

wx.navigateBack({ delta: 1});

}

});

},

fail: function(){

wx.showToast({

title: '网络信号差',

})

}

});//保存数据

},


回答关注问题邀请回答
收藏
登录 后发表内容
问题标签