kvdata多个key时应该怎么写啊?~~
我这么写会报错,说“KVDataList must be an Array”
let kvdata =new Array();
let data1={key:rankString,value:this.rankScore};
let data2={key:rankTimeString,value:date.getTime()};
kvdata.push(data1);
kvdata.push(data2);
wx.setUserCloudStorage(kvdata);
let gameScoreData = {
wxgame: {
score:
16
,
update_time:
new
Date
().getTime(),
},
cost_ms:
36500
}
let userKVData = {
key:
"score"
,
value: JSON.stringify(gameScoreData),
}
wx.setUserCloudStorage({
KVDataList: [userKVData],
success:
function
(res) {
console.log(
'--success res:'
, res);
},
fail:
function
(res) {
console.log(
'--fail res:'
, res);
},
complete:
function
(res) {
console.log(
'--complete res:'
, res);
},
});
测过了,能用。
setUserCloudStorage 的调用写错了,应该是这样
wx.setUserCloudStorage({
KVDataList: yourKVDataList,
success: res => console.log(res),
fail: res => console.log(res)
})
至于拉取为 0,应该就是你之前 set 失败所以没有数据写入。
还有,要拉取的时候要怎么写呢?
wx.getFriendCloudStorage(
{
keyList: ["rankScore","rankTime"],
success: res => {
let data = res.data
this.drawRankList(data)
},
})
这么写得到的KVDataList元素个数是0 (KVDataList: Array(0))