Meteor.call(..) 会导致刷新页面
Meteor.call(...) causes refresh the page
我正在使用Meteor开发一个非常简单的投票应用程序。
voteapp.meteor.com
单击投票按钮(选择选项后显示)后,页面将刷新。
点击事件:
Template.poll.events({
"click input.inc": function (event) {
// Prevent default browser form submit
event.preventDefault();
Meteor.call('voteForAnswer', Session.get("selectedanswer"), function (error, result) {
if (error) {
Session.set("voteError", error.reason);
}
else {
Session.set("voteError", null);
Session.set("selectedpoll", result);
}
});
}
});
流星呼叫功能:
'voteForAnswer': function (id, vote) {
var answer = Answers.findOne(id);
var poll = Polls.findOne(answer.poll);
if (poll && answer) {
Answers.update(answer, { $inc: { score: 1 } }, function (error) {
if (error) {
throw new Meteor.Error(411, "Answer could not be updated.");
}
});
Polls.update(poll, { $inc: { sum: 1 }, $set: { lastActivity: new Date() } }, function (error) {
if (error) {
throw new Meteor.Error(411, "Poll could not be updated. " + poll.name);
}
});
poll = Polls.findOne(poll._id);
var answers = Answers.find({ poll: poll._id }).fetch();
answers.forEach(function (ans) {
ans.score && Answers.update(ans, { $set: { percent: Math.round((parseInt(ans.score) / parseInt(poll.sum)) * 100) } });
});
poll.answers = Answers.find({ poll: poll._id }, { sort: { score: -1 } }).fetch();
}
return poll;
}
也:
if (Meteor.isClient) {
Meteor.subscribe("polls");
Meteor.subscribe("answerswers");
和:
if (Meteor.isServer) {
Meteor.publish("polls", function () {
return Polls.find();
});
Meteor.publish("answerswers", function () {
return Answers.find();
});
}
我发现了问题。我将 Meteor.methods(...) 移到 if (Meteor.isServer) { ... } 块。现已修复。
相关文章:
- 强制模板刷新ember.js
- 如何通过ajax刷新JSF填充的javascript变量
- 如何解决Yii中的页面刷新问题
- Jquery提交表单而不刷新
- 刷新页面后会出现警报
- 刷新后保留对网页的更改
- 如何在不刷新页面的情况下更新显示框
- 重定向时角度刷新浏览器
- 如何防止jQueryonclick事件中的Ruby方法在页面刷新时执行
- Javascript,输出结果后页面不断刷新
- $(document).height()在刷新时随机化值(Safari 5.1.10)
- 刷新父窗口后无法关闭窗口
- 刷新页面时hasClass不起作用
- X秒后刷新select元素
- chart.series[id].remove()无法刷新高位图表/高位股票中其他系列的图例属性
- 触发媒体查询断点时刷新页面
- 如何刷新列表框内容onclick或blur事件
- 如何在火狐浏览器中禁用F5和刷新
- 刷新后,setTimeout将工作或不工作
- Meteor.call(..) 会导致刷新页面