Reputation: 7362
This is the strangest thing, for some reason even with autopublish turned on, I cannot access the collection from browser console. The code below is a simple list program where you can enter items into the collection and it will appear as a list on the screen. In console when I try to access the database by typing People.find() or People.find().fetch() it brings up an error 'ReferenceError: Can't find variable: People'
How come this is happening I have autopublish on, so I thought I can access the collection from the client?
Code:
var People = new Meteor.Collection("people");
if (Meteor.isClient) {
console.log(People.find());
Template.personList.people = function () {
return People.find();
};
Template.personForm.events({
'click button': function(e, t) {
var el = t.find("#name");
People.insert({ name: el.value });
el.value = "";
}
});
Template.person.editing = function () {
return Session.get("edit-" + this._id);
};
Template.person.rendered = function () {
var input = this.find("input");
if(input) {
input.focus();
}
};
Template.person.events({
'click .name': function (e, t) {
Session.set("edit-" + t.data._id, true);
},
'keypress input': function (e, t) {
if (e.keyCode == 13) {
People.update(t.data._id, { $set: { name: e.currentTarget.value }});
Session.set("edit-" + t.data._id, false);
}
},
'click .del': function (e, t) {
People.remove(t.data._id);
}
});
}
Upvotes: 4
Views: 3174
Reputation: 75945
You don't have to use @
unless you're using coffeescript. In plain javascript remove the var
so your variable can be accessed anywhere outside of the file (including the chrome console):
var People = new Meteor.Collection("people");
becomes
People = new Meteor.Collection("people");
To use coffeescript use a .coffee
extension and run meteor add coffeescript
to allow meteor to compile coffeescript files to js files
Upvotes: 13
Reputation: 1148
to answer your question @ is used for CoffeeScript (Javascript Alternative), you can add the meteor package for it and then write your app in that language. Learn about it here http://coffeescript.org
Upvotes: 2