[英]Setting simple events in meteor
我在Meteor中嘗試Leaderboard的例子,但我在設置click事件時做錯了。 在這個例子中,我有三個按鈕,一個用於按列更改排序,另一個用於向每個人添加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>
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.