Когда я определяю переменную 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 Primer for Meteor] (https://www.discovermeteor.com/blog/javascript-for-meteor/) – KyleMit