【发布时间】:2015-12-03 22:51:34
【问题描述】:
我正在使用 Meteor 创建一个网络应用程序,允许用户创建和投票投票。
目前我正在尝试让用户能够对投票进行投票,但我没有运气。这是我目前的方法:
Template.PollParticipate.events({
'click .vote': function(event) {
event.preventDefault();
var target = $(event.target);
var pollID = $(this).parent('.poll-card').data('id');
var voteID = $(this).data('id');
var voteString = 'options.' + voteID + '.votes';
var action = {};
action[voteString] = 1;
Polls.update(
{_id: pollID},
{$inc: action}
);
}
});
这是模板html:
<template name="PollParticipate">
<div class="poll-card text-center" data-id="{{ _id }}">
<h3>{{question}}</h3>
<form>
<div>
{{#each options}}
<input type="radio" name="option" value={{option}} data-id="{{ _index }}">{{option}}
{{/each}}
</div>
<button type="submit" class="vote">Submit</button>
</form>
</div>
</template>
在这种情况下,当用户单击投票按钮时,该方法将查找父项的 id 并将其存储在变量中。它还将尝试查找所选元素的索引(使用单选按钮)。然后通过它,使投票计数器更新一。
不幸的是,这没有发生。
整个项目的代码可以找到:https://github.com/smeloa/fcc-voting-app
谢谢!
【问题讨论】: