gpt4 book ai didi

javascript - 在 meteor 中设置简单事件

转载 作者:可可西里 更新时间:2023-11-01 02:58:16 24 4
gpt4 key购买 nike

我正在 Meteor 中尝试 Leaderboard 的示例,但我在设置点击事件时做错了。在此示例中,我有三个按钮,一个用于更改按列排序,另一个用于为每个人添加 5 个奖励积分。

这是 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>

这是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}});
});
}

调用 Session.set('orderby', 'name');在控制台中工作并相应地更新 html 但单击按钮不会。那我错过了什么?

谢谢

最佳答案

带有选择器的事件映射不会匹配模板中的顶级元素。这是我们会尽快解决的问题。

虽然有一个简单的解决方法。将您的排序器模板包装在 <div> 中.

http://docs.meteor.com/#eventmaps

关于javascript - 在 meteor 中设置简单事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10112930/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com