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) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
var success = false;
|
var action;
|
||||||
reply.ups = reply.ups || [];
|
reply.ups = reply.ups || [];
|
||||||
if (reply.ups.indexOf(userId) === -1) {
|
var upIndex = reply.ups.indexOf(userId);
|
||||||
|
if (upIndex === -1) {
|
||||||
reply.ups.push(userId);
|
reply.ups.push(userId);
|
||||||
success = true;
|
action = 'up';
|
||||||
|
} else {
|
||||||
|
reply.ups.splice(upIndex, 1);
|
||||||
|
action = 'down';
|
||||||
}
|
}
|
||||||
reply.save(function () {
|
reply.save(function () {
|
||||||
res.send({
|
res.send({
|
||||||
success: success
|
success: true,
|
||||||
|
action: action,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -328,10 +328,16 @@
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
}).done(function (data) {
|
}).done(function (data) {
|
||||||
if (data.success) {
|
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;
|
||||||
$this.addClass('uped');
|
if (data.action === 'up') {
|
||||||
} else {
|
$this.next('.up-count').text(currentCount + 1);
|
||||||
alert('重复投票。');
|
$this.addClass('uped');
|
||||||
|
} else {
|
||||||
|
if (data.action === 'down') {
|
||||||
|
$this.next('.up-count').text(currentCount - 1);
|
||||||
|
$this.removeClass('uped');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user