亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

評論+評分=>可以上傳到云數據庫 圖片單獨=>可以上傳到云存儲 評論+評分+圖片=>可以上傳圖片到云存儲但是數據庫沒有任何記錄

在線請求幫助

正在回答

2 回答

我也是,圖片的fileIds上傳數據庫沒有,云存儲那邊是有圖片的。

const db = wx.cloud.database(); // 初始化數據庫

// pages/comment/comment.js

Page({


/**

? * 頁面的初始數據

? */

data: {

detail: {},

movieId: -1,

content: "",

score: 0,

images: [],

pic: []

},

//評價

onContentChange: function(event) {

this.setData({

content: event.detail

})

},

//評分

onScoreChange: function (event) {

this.setData({

score: event.detail

})

},

//上傳圖片

uploadImg: function() {

wx.chooseImage({

count: 1,

sizeType: ['original', 'compressed'],

sourceType: ['album', 'camera'],

success: res => {

// tempFilePath可以作為img標簽的src屬性顯示圖片

const tempFilePaths = res.tempFilePaths;

this.setData({

images: this.data.images.concat(tempFilePaths)

})

}

})

},


submit:function() {

wx.showLoading({

title: '評論中',

});

let promiseArr = [];

for(let i = 0;i< this.data.images.length;i++) {

promiseArr.push(new Promise((reslove, reject) => {

let item = this.data.images[i];

let suffix = /\.\w+$/.exec(item)[0];//返回文件拓展名

wx.cloud.uploadFile({

cloudPath: new Date().getTime() + suffix, // 上傳至云端的路徑

filePath: this.data.images[i], // 小程序臨時文件路徑

success: res => {

// 返回文件 ID

console.log(res.fileID)

this.setData({

pic: this.data.pic.concat(res.fileID),

});

console.log(this.data.pic);

reslove();

},

fail: console.error,

})

})

)

};


Promise.all(promiseArr).then(res => {

// 插入數據

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

data: {

content: this.data.content,

score: this.data.score,

movieid: this.data.movieId,

pic: this.data.pic

}

}).then(res => {

wx.hideLoading();

wx.showToast({

title: '評價成功',

})

}).catch(err => {

wx.hideLoading();

wx.showToast({

title: '評價失敗',

})

})


});

},


/**

? * 生命周期函數--監聽頁面加載

? */

onLoad: function (options) {

console.log(options);

this.setData({

movieId: options.movieid

});

wx.showLoading({

title: '加載中',

})

//console.log(options);

wx.cloud.callFunction({

name: 'getDetail',

data: {

movieid: options.movieid

}

}).then(res => {

// console.log(res);

this.setData({

detail: JSON.parse(res.result)

});

wx.hideLoading();

}).catch(err => {

console.error(err);

wx.hideLoading();

});

},


/**

? * 生命周期函數--監聽頁面初次渲染完成

? */

onReady: function () {


},


/**

? * 生命周期函數--監聽頁面顯示

? */

onShow: function () {


},


/**

? * 生命周期函數--監聽頁面隱藏

? */

onHide: function () {


},


/**

? * 生命周期函數--監聽頁面卸載

? */

onUnload: function () {


},


/**

? * 頁面相關事件處理函數--監聽用戶下拉動作

? */

onPullDownRefresh: function () {


},


/**

? * 頁面上拉觸底事件的處理函數

? */

onReachBottom: function () {


},


/**

? * 用戶點擊右上角分享

? */

onShareAppMessage: function () {


}

})


1 回復 有任何疑惑可以回復我~

評論分為兩步,第一步是上傳圖片到云存儲,第二部是上傳數據到云數據庫。請分別檢查兩個步驟,并查看調試器控制臺中是否有錯誤信息。把錯誤截圖出來能夠更快的定位到問題。

0 回復 有任何疑惑可以回復我~
#1

qq_Shinesobrigh_0

已經解決,promise部分的問題,已經解決。
2019-08-02 回復 有任何疑惑可以回復我~
#2

weixin_慕虎8531678 回復 qq_Shinesobrigh_0

你好 你是怎么解決的呢
2019-08-25 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

評論+評分=>可以上傳到云數據庫 圖片單獨=>可以上傳到云存儲 評論+評分+圖片=>可以上傳圖片到云存儲但是數據庫沒有任何記錄

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號