// pages/postdetail/postsdetail.js
var postsdata = require('../../data/posts.data.js')
Page({
onLoad: function(option) {
var postId = option.id;
var postscollection = wx.getStorageSync('posts-collections');
console.log(postscollection);
if (postscollection) {
var postcollection = postscollection[postId];
if (postcollection) {
this.setData({
collected: postcollection
})
}
} else {
wx.setStorageSync('posts-collections', {});
postscollection[postId] = false;
var postcollection = postscollection[postId];
}
this.setData({
postId: postId,
postscontent: postsdata.postsList[postId],
})
},
onCollectionTap: function(event, postId) {
var postscollection = wx.getStorageSync('posts-collections');
var postcollection = postscollection[postId];
postcollection = !postcollection;
postscollection[postId] = postcollection;
this.setData({
collected: postcollection
})
wx.setStorageSync('posts-collections', postscollection);
}
})
这里哪来的undefined:true ????而且我没有实现功能 下次点进去还是未收藏
4年同步微信官方迭代,累计20000+人学习, 比微信官方更火爆!
了解课程