3
當我定義變量lists
如下圖所示,在控制檯輸入lists
,我得到的錯誤ReferenceError: lists is not defined
定義變量Meteor.js
var lists = new Meteor.Collection('Lists');
if (Meteor.isClient) {
Template.hello.greeting = function() {
return "my list.";
};
Template.hello.events({
'click input' : function() {
// template data, if any, is available in 'this'
if (typeof console !== 'undefined')
console.log("You pressed the button");
}
});
}
if (Meteor.isServer) {
Meteor.startup(function() {
// code to run on server at startup
});
}
如果我聲明lists
作爲一個全局變量它僅適用:
lists = new Meteor.Collection('Lists');
問題:爲什麼它必須是全局範圍?
[流星JavaScript入門](https://www.discovermeteor.com/blog/javascript-for-meteor/) – KyleMit