【发布时间】:2016-03-17 12:26:54
【问题描述】:
我是 Meteor 的新手,并尝试遵循“您的第一个 Meteor 应用程序”: http://meteortips.com/first-meteor-tutorial/ 我试图定义一个辅助函数。 在我写的html文件中:
<head>
<title>Leaderboard</title>
</head>
<body>
<h1>Leaderboard</h1>
{{> leaderboard}}
</body>
<template name="leaderboard">
<!-- Hello World -->
<!-- {{player}} -->
<!-- {{otherHelperFunction}} -->
<ul>
{{#each player}}
<li>{{name}}:{{score}}</li>
{{/each}}
</ul>
{{numOfPlayer}}
</template>
在我写的JS文件中:
if(Meteor.isClient){
Template.leaderboard.helpers({
"player": function(){
// return "Some other text";
return PlayersList.find();
},
"numOfPlayer": function(){
// return "Some other text";
return PlayersList.find().count();
},
"otherHelperFunction": function(){
return "Some other funciton";
}
})
Template.leaderboard.player = function(){
return "Some other text";
}
// console.log("Hello client");
}
if(Meteor.isServer){
console.log("Hello server");
}
PlayersList = new Mongo.Collection('players');
所以在客户端部分的 JS 文件中,我定义了两个“播放器”辅助函数:一个是旧方式,一个是新方式。旧方式实际上是我忘记注释掉但是当我运行这个项目时,网站竟然以“新方式”执行,并且似乎旧方式定义的“播放器”辅助功能并没有影响项目all 并且编译器没有说有任何错误或歧义(因为您可以看到这两个“播放器”辅助函数是为不同的功能定义的)。这是什么原因?是不是因为旧方式定义的辅助函数被新的辅助函数覆盖了?
【问题讨论】:
标签: javascript meteor helper