先週、Node.js でコーディングを開始しました。複数のテーブルにクエリを実行する JSON を生成するコードを作成し、not sure if this is correct way of coding asynchronously
build_actor(post, function(actor){
build_post_object(post, function(post_object){
build_post_attachments(post, function(attachments){
build_post_comments(post, function(comments){
var post_obj = {};
post_obj.actor = actor;
post_obj.object = post_object;
post_obj.attachments = attachments;
post_obj.comments = comments;
console.log(JSON.stringify(post_obj)); // generates JSON
});
});
});
});
function build_actor(post, callback){
//query
callback(actor);
}
function build_post_object(post, callback){
//query
callback(post_object);
}
function build_post_attachments(post, callback){
//query
callback(attachments);
}
function build_post_comments(post, callback){
//query
callback(comments);
}
複数のクエリを記述して JSON を構築するためのより良い方法があれば教えてください。