我试图在'会话中执行某些程序。我创建了一个名为' leaderboard'。
的项目执行此排行榜会显示一些未定义的'控制台日志。知道为什么吗?
这是我的代码:
PlayerList = new Mongo.Collection('players');
if (Meteor.isClient) {
Template.leaderboard.helpers({
'player': function() {
return PlayerList.find()
},
});
Template.leaderboard.events({
'click .player': function() {
var playerId = this._id;
Session.set('selectedPalyer', playerId);
var selectedPlayer = Session.get('selectedPlayer');
console.log(selectedPlayer);
}
});
}
<head>
<title>Leaderboard</title>
</head>
<body>
<h1>Leaderboard</h1>
{{> leaderboard}}
</body>
<template name="leaderboard">
<ul>
{{#each player}}
<li class="player">{{name}}: {{score}}</li>
{{/each}}
</ul>
</template>
答案 0 :(得分:0)
您的Session
密钥中有拼写错误。
只需将Session.set('selectedPalyer', playerId);
替换为Session.set('selectedPlayer', playerId);
,即可开始使用:
PlayerList = new Mongo.Collection('players');
if (Meteor.isClient) {
Template.leaderboard.helpers({
'player': function () {
return PlayerList.find();
}
});
Template.leaderboard.events({
'click .player': function () {
var playerId = this._id;
Session.set('selectedPlayer', playerId);
var selectedPlayer = Session.get('selectedPlayer');
console.log(selectedPlayer);
}
});
}