我有以下代码:
Template.leaderboard.players = function() {
return Players.find({}, {sort: {score: -1, name: 1}});
};
Template.leaderboard.selected_name = function() {
var player = Players.findOne(Session.get("selected_player"));
return player && player.name;
};
我想更清楚地组织它:
Template.leaderboard = {
players: function() {
return Players.find({}, {sort: {score: -1, name: 1}});
},
selected_name: function() {
var player = Players.findOne(Session.get("selected_player"));
return player && player.name;
}
};
问题是(我相信控制台中的错误)这会覆盖Template.leaderboard
对象的所有现有方法并替换它。
是否有可能将这些方法添加到对象中,同时使用上面显示的符号保留现有方法?