When using Meteor, I can’t access the collection from the client console?

This is the weirdest thing, for some reason, even with autocompletion enabled, I can’t access the collection from the browser console. The code below is a simple list program in which you can enter items into the collection, and it will be displayed as a list on the screen. In the console, when I try to access the database by typing People.find () or People.find (). Fetch () throws an error 'ReferenceError: cannot find variable: People'

How did it happen that I have auto-update, so I thought that I could access the collection from the client?

the 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); } }); } 
+4
source share
2 answers

You do not need to use @ unless you are using coffeescript. In simple javascript, remove var so your variable can be accessed anywhere outside the file (including the chrome console):

 var People = new Meteor.Collection("people"); 

becomes

 People = new Meteor.Collection("people"); 

To use coffeescript, use the .coffee extension and run meteor add coffeescript to allow the meteorite to compile coffeescript files into js files.

+13
source

to answer your question @, used for CoffeeScript (Javascript Alternative), you can add a meteorite package for it, and then write your application in this language. Find out about it here http://coffeescript.org

+2
source

Source: https://habr.com/ru/post/1495157/


All Articles