私は他のスタックオーバーフローの問題を見てきましたが、私はまだ私のことを理解できません。私は、ブラウザのコンソールでこのエラーを取得しています:Meteor/Javascript関数のエラー - TypeError:コールバックが関数ではありません
Exception in delivering result of invoking 'formMethod1': TypeError: callback is not a function
私は以下のコードとラインエラーの参照にコメントを入れています。 "err"オブジェクトは渡されていないようですが、コールバックは実際に呼び出されていて、すべてが処理されます。エラーは検出されません。
submitForm1(entry,
\t processForm1(err,res,entry,function(err,res){
\t \t //Done processing
\t \t console.log(err); //Doesn't work
\t \t console.log(res); //Doesn't work
\t \t console.log("Done"); //Works
})
) \t \t \t
function submitForm1(entry, callback) {
Meteor.call('formMethod1', {
params: {
user: Meteor.user().username,
activity: entry
}
}, function(err,res){
if(err){
\t console.log(err) //Works
callback(err, res, entry) //This is where the error happens
} else{
callback(undefined, res, entry)
}
}
);
}
function processForm1(err, res, entry, callback) {
\t console.log(err); //Doesn't work
\t console.log(res); //Works
\t console.log(entry); //Works
if (err) {
if (err.error == "1001") { //Activity not found
//Handle Error
callback("Activity Not Found");
} else {
//Handle Error
callback(err.message);
}
} else { //No Errors
callback(undefined,"Submitted");
}
}
EDIT:あなたのすべては私が正しい方向に向かってしまいました。
submitForm1(entry, function(err,res){
processForm1(err,res,entry,function(err,res){
//Done processing
\t \t console.log(err);
\t \t console.log(res);
\t \t console.log("Done");
})
});
processForm1は関数を返しません。それを呼び出してその結果をコールバックとして使用するには、関数を返す必要があります。 –
submitForm1を呼び出すときに2つのレベルのコールバックを使用していますが、それはロジックを少し複雑にしているからです。 – Yaser