我已经在Keystone JS中使用如下所示的空表单创建了一个like按钮(我仅包括其骨架)。我有三个问题:
哈巴狗片
form#like(method='get', style="display:inline;", target='like_iframe')
input(type='hidden', name='action', value='like')
// Empty iframe to redirect forms -> no page refresh.
iframe#like_iframe(name='like_iframe', style='display: none;')
a#like-unlike(href='').not-clicked
i#like-icon.ti-heart
jquery片段:
$("#like-unlike").click(function(e) {
document.getElementById('like').submit();
});
和post.js视图片段:
// Add Like
view.on('get', {action: 'like'}, function (next) {
console.log('clicked');
locals.data.post.likes+=1;
locals.data.post.save();
next();
});