我是Meteor的新手,我还在努力了解一些事情是如何运作的。 为了更好地理解语言和工作流程,使用警报和打印消息到控制台是一个好主意。 但我坚持一些事情
我想知道这是一种将消息打印到控制台的简单方法。 例如,当我提交表单时,我无法发出警报,我无法看到我打印的浏览器控制台消息。
我怎么能做这种事呢? 也许打印消息到运行服务器的系统控制台? 有关如何使用控制台,显示消息和警报的任何进一步建议?
I am new to Meteor and I'm still trying to understand how a few things work. To have a better understanding of the language and the workflow, using alerts and printing messages to the console is a great idea. But I'm stuck on a few things
I wonder if the is a simple and default way to print messages to the console. For example, when I submit a form I can't make an alert to work and I can't see the the browser's console message I printed.
How can I do this kind of thing? Maybe printing messages to the system console where the server is running? Any further advise on how to use console, showing messages and alerts?
最满意答案
您基本上可以使用console.log()在javascript中将日志打印到控制台,这基本上就是这个函数所代表的含义。
如果你在期待它时没有在chrome控制台中看到任何结果,可能有以下几个原因:
执行代码时未访问console.log() 。 确保它不在错误的条件范围内例:
if (false) console.log('print me!'); // this desperate log will never see the light of day else console.log('No, print me!'); // this one always will 您的console.log()在服务器端运行,因此它的输出将打印在您的服务器日志上,通常是您在运行流星的一侧的终端窗口例:
if (Meteor.isServer) console.log('I\'m on the server!'); // this log will print on the server console if (Meteor.isClient) console.log('I\'m on the client!'); // this log will print on the chrome console console.log('I\'m omnipresent'); // this log will print on both 如果您提到undefined弹出错误,则您尝试打印的变量尚未定义。 确保在打印之前设置了变量例:
> var real_friend = "Bobby"; > console.log(real_friend); "Bobby" > console.log(imaginary_friend); Error: 'imaginary_friend' is undefined.You would basically use console.log() to print logs to the console in javascript, that is basically what this function stands for.
If you do not see any results in the chrome console while expecting it, it can be for a few reasons:
Your console.log() is not reached when executing your code. Make sure it is not in the wrong conditional scopeExample:
if (false) console.log('print me!'); // this desperate log will never see the light of day else console.log('No, print me!'); // this one always will Your console.log() is ran on server side, therefore its output will be printed on your server logs, usually the terminal window you have on the side running meteorExample:
if (Meteor.isServer) console.log('I\'m on the server!'); // this log will print on the server console if (Meteor.isClient) console.log('I\'m on the client!'); // this log will print on the chrome console console.log('I\'m omnipresent'); // this log will print on both If you have an error mentionning undefined popping up, the variable you are trying to print has not yet been defined. Make sure your variable is set before printing itExample:
> var real_friend = "Bobby"; > console.log(real_friend); "Bobby" > console.log(imaginary_friend); Error: 'imaginary_friend' is undefined.更多推荐
发布评论