Answers.js
const { ups , answer, displayName, photoURL, userid, increment, answerid, index, answers} = props;
const upvote = () => {
const newarr = answers.map(item => item.voters);
console.log("new arr is " + newarr)
// console记录由逗号分隔的字符串而不是选民数组
authUser && increment(index);
}
app.js
increment = (index) => {
let answers = this.state.answers.slice();
++answers[index].ups;
answers[index].voters.push(answers[index].userid)
this.setState({answers})
}
这是答案的样子
makeAnswer() {
const answer = ({ answer:this.state.answer, belongsTo:this.state.openedPost, ups:0, isAccepted: false, id:this.getPostId(), userid:this.context.authUser.uid, displayName:this.context.authUser.displayName, photoURL:this.context.authUser.photoURL, date:Date.now(), voters:[] })
return answer;
}
答案 0 :(得分:2)
由于连接,您的newarr
会转换为字符串;这样做:
console.log("new arr is", newarr)