[英]Meteor method giving error
I am new to Meteor. 我是新来的流星。 I am trying to call a Meteor.method('addTask') from an event helper and I keep getting the error: "Error invoking Method 'addTask': Method 'addTask' not found [404]". 我试图从事件助手中调用Meteor.method('addTask'),但不断收到错误消息:“调用方法'addTask'时出错:未找到方法'addTask'[404]”。 I will put my code below: 我将代码放在下面:
Template.add_task.events({
'submit .js-emoticon': function(event){
event.preventDefault();
// console.log('clicked');
// var text = event.target.text.value;
// $('#text_display').html(text);
// $('#text_display').emoticonize();
Meteor.call("addTask");
}
}); });
And the Meteor.method here: 还有Meteor.method在这里:
Meteor.methods({
'addTask':function(){
var task = event.target.text.value;
Items.insert({
created:new Date().toLocaleDateString("en-US"),
task:task
});
console.log(task);
}
}); });
Both are on the main.js in the client folder. 两者都在client文件夹中的main.js上。 I have tried to put the method on the server/main.js and I get an error: "Error invoking Method 'addTask': Internal server error [500]". 我尝试将方法放在server / main.js上,但出现错误:“调用方法'addTask'时出错:内部服务器错误[500]”。
If it is on the client it will log the value of #text to console but on the server it doesn't even do that. 如果在客户端,它将把#text的值记录到控制台,但在服务器上甚至不这样做。
As I said I have been learning Meteor and researched this as the way to do it. 正如我所说的,我一直在学习流星,并对其进行了研究。 I am obviously missing something and can't figure it out. 我显然缺少某些东西,无法解决。 Any help would be appreciated. 任何帮助,将不胜感激。
You are trying to look at a DOM element from your server code. 您正在尝试从服务器代码中查看DOM元素。 You need to get that element on the client and then pass it to the method, which you can put in the /lib
folder for latency compensation if you wish. 您需要在客户端上获取该元素,然后将其传递给该方法,您可以根据需要将该方法放在/lib
文件夹中以进行延迟补偿。
Client: 客户:
Template.add_task.events({
'submit .js-emoticon': function(event){
event.preventDefault();
var task = event.target.text.value;
Meteor.call("addTask",task);
}
});
Server: 服务器:
Meteor.methods({
'addTask':function(task){
check(task,String);
Items.insert({ created: new Date(), task: task });
console.log(task);
}
});
You never want to convert your dates to strings when you persist them in mongo. 当您将日期保留在mongo中时,您永远都不想将日期转换为字符串。 That makes searching on dates impossible. 这使得不可能搜索日期。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.