我在我的lib文件夹中定义了一个没有var的数组“userCollections”,用新的集合填充它:
userCollections = [];
Collectionlist = CustomCollections.find({});
Collectionlist.forEach(function(col) {
userCollections[col.name] = new Meteor.Collection(col.name);
Meteor.publish(col.name, function(){
return Mongo.Collection.get(col.name).find({});
});
console.log(userCollections[col.name]);
});
但在我的客户端文件夹中,我的数组是空的。
console.log(userCollections);
为什么?
问题是:
userCollections = [];
userCollections["0"] = "0_test";
Collectionlist = CustomCollections.find({});
Collectionlist.forEach(function(col) {
userCollections["1"] = "1_test";
console.log(userCollections); //----> array -> "1":"1_test"
});
在我的CollectionCursor-forEach和我的服务器文件夹中定义了数组
console.log(userCollections); //----> array -> "0":"0_test"
但在我的forEach和客户端文件夹之外,数组是未定义的... 有范围问题吗?