检查很多遍了。 目前是点击收藏以后可以收藏,但是点击下一篇文章收藏以后,前一篇文章的收藏就被替换掉了。(缓存只存了最新的那一次点击的状态)另外已收藏的图标再次点击无法变成未收藏。不知道怎么回事!谢谢!
onLoad: function (option) {
var postId = option.id;
this.data.currentPostId = postId;
var postData = postsData.postList[postId];
this.setData({
postData: postData});
var postsCollected =wx.getStorageSync("posts_Collected")
if (postsCollected){
var postCollected=postsCollected[postId]
if (postCollected){
this.setData({
collected: postCollected
})
}
}
else{
var postsCollected={};
postsCollected[postId]=false;
wx.setStorageSync('posts_Collected', postsCollected);
}
},
onCollectionTap: function(event){
var postsCollected = wx.getStorageInfoSync("posts_Collected");
var postCollected = postsCollected[this.data.currentPostId];
postCollected=!postCollected;
// 更新缓存
postsCollected[this.data.currentPostId] = postCollected;
// 更新缓存
wx.setStorageSync("posts_Collected", postsCollected);
// 更新数据绑定
this.setData({
collected: postCollected
})
}
4年同步微信官方迭代,累计20000+人学习, 比微信官方更火爆!
了解课程