【发布时间】:2016-10-04 16:50:00
【问题描述】:
我想限制用户只为一个问题投票一次 $本地存储。
这是我的代码: HTML:
<ul>
<li ng-repat="question in questions"> {{question.text}}
<button ng-click="upvote(question)">Vote</button>
</li>
JS:
$scope.upvote = function(question){
var votedQuestions = [];
$localStorage.votedQuestions = votedQuestions;
if($localStorage.votedQuestions.indexof(question._id) === -1){
$localStorage.votedQuestions.push(question._id);
console.log("Thanks for Voting");
}
else {
console.log("You already voted to this question");
}
}
}
它给了我错误,比如 $localStorage.votedQuestions.indexof is not a function
它没有存储多个问题,它只是在点击其他问题时更新本地存储数组中的问题 ID
【问题讨论】:
标签: javascript angularjs local-storage