请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

Setting data field "collected" to undefined is invalid.

var postsData = require('../../../data/posts-data.js')
Page({
data: {
},

onLoad: function(option) {
var postId = option.id;
var postData = postsData.postList[postId]; 
this.setData({
postData: postData,
postId: postId
})
var postsCollected = wx.getStorageSync('posts_collected')
if (postsCollected) {
var postCollected = postsCollected[postId]
this.setData({
collected: postCollected
})
} else { 
var postsCollected = {}; 
postsCollected[postId] = false;
wx.setStorageSync('posts_collected', postsCollected);
}
},

onColletionTap: function(event) {
var postsCollected = wx.getStorageSync('posts_collected');
var postCollected = postsCollected[this.setData.postId];
postCollected = !postCollected;
postsCollected[this.setData.postId] = postCollected; 
wx.setStorageSync('posts_collected', postsCollected); 
this.setData({
collected: postCollected
})
},
})
<view class='container'>
<image class='head-image' src='{{postData.img.headImgSrc}}'></image>
<image class='audio' src='../../../images/music-start.png'></image>
<view class='author-date'>
<image class='avatar' src='{{postData.img.avatarDetail}}'></image>
<text class='author'>{{postData.author}}</text>
<text class='const-text'>发表于</text>
<text class='date'>{{postData.dateTime}}</text>
</view>
<text class='title'>{{postData.title}}</text>
<view class='tool'>
<view class='circle-img'>
<image wx:if='{{collected}}' catchtap='onColletionTap' src='../../../images/shoucang.png'></image>
<image wx:else catchtap='onColletionTap' src='../../../images/shoucang-anti.png'></image>
<image catchtap='onShareTap' class='share-img' src='../../../images/fenxiang.png'></image>
</view>
<view class='horizon'></view>
</view>
<text class='detail'>{{postData.detail}}</text>
</view>

https://img1.sycdn.imooc.com//szimg/5b4eb482000171e910170308.jpg

在点击某篇文章进入文章详情时就弹出了错误,“Setting data field "collected" to undefined is invalid.”

正在回答 回答被采纳积分+3

2回答

慕运维5448999 2018-09-16 13:11:07

同样问题,求解答

0 回复 有任何疑惑可以回复我~
7七月 2018-07-19 10:11:09

错误给的很明显,你需要看看为什么出现undefined。

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信