mirror of
https://github.com/cnodejs/nodeclub.git
synced 2025-12-08 19:55:55 +00:00
hotfix
This commit is contained in:
parent
127f060ca3
commit
2267b8c306
@ -211,15 +211,20 @@ exports.up = function (req, res, next) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
var success = false;
|
||||
var action;
|
||||
reply.ups = reply.ups || [];
|
||||
if (reply.ups.indexOf(userId) === -1) {
|
||||
var upIndex = reply.ups.indexOf(userId);
|
||||
if (upIndex === -1) {
|
||||
reply.ups.push(userId);
|
||||
success = true;
|
||||
action = 'up';
|
||||
} else {
|
||||
reply.ups.splice(upIndex, 1);
|
||||
action = 'down';
|
||||
}
|
||||
reply.save(function () {
|
||||
res.send({
|
||||
success: success
|
||||
success: true,
|
||||
action: action,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -328,10 +328,16 @@
|
||||
method: 'POST',
|
||||
}).done(function (data) {
|
||||
if (data.success) {
|
||||
$this.next('.up-count').text((+$this.next('.up-count').text || 0) + 1);
|
||||
var currentCount = Number($this.next('.up-count').text().trim()) || 0;
|
||||
if (data.action === 'up') {
|
||||
$this.next('.up-count').text(currentCount + 1);
|
||||
$this.addClass('uped');
|
||||
} else {
|
||||
alert('重复投票。');
|
||||
if (data.action === 'down') {
|
||||
$this.next('.up-count').text(currentCount - 1);
|
||||
$this.removeClass('uped');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user