[英]Setting simple events in meteor
I'm trying out Leaderboard's example in Meteor but i'm doing something wrong in setting the click event. 我在Meteor中尝试Leaderboard的例子,但我在设置click事件时做错了。 In this example, I have three buttons, one to change the sort by column, another to add 5 bonus points to everyone. 在这个例子中,我有三个按钮,一个用于按列更改排序,另一个用于向每个人添加5个奖励积分。
Here's the html: 这是html:
<div id="outer">
{{> sorter}}
{{> leaderboard}}
</div>
<template name="sorter">
<span>Sorted by {{sortedBy}}</span>
{{#if sortByName}}
<input type="button" id="sortScore" value="sort by score" />
{{else}}
<input type="button" id="sortName" value="sort by name" />
{{/if}}
<input type="button" class="incAll" value="5 bonus points to all" />
</template>
And here's the js: 这是js:
Template.sorter.events = {
'click #sortName': function(){
Session.set('orderby', 'name');
},
'click #sortScore': function(){
Session.set('orderby', 'score');
},
'click input.incAll': function(){
Players.find().forEach(function(player){
Players.update(player._id, {$inc: {score: 5}});
});
}
} }
Calling Session.set('orderby', 'name'); 调用Session.set('orderby','name'); in the console works and updates the html accordingly but clicking in the buttons doesn't. 在控制台中工作并相应地更新html,但没有点击按钮。 So what am I missing? 那我错过了什么?
Thanks 谢谢
Event maps with selectors won't match top-level elements in a template. 带选择器的事件映射与模板中的顶级元素不匹配。 This is something we will fix ASAP. 这是我们将尽快解决的问题。
There's an easy workaround though. 虽然有一个简单的解决方法。 Wrap your sorter template in a <div>
. 将您的分拣机模板包装在<div>
。
http://docs.meteor.com/#eventmaps http://docs.meteor.com/#eventmaps
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.