简体   繁体   English

NodeJS和MySQL的嵌套回调

[英]Nested Callbacks with NodeJS & MySQL

I have come to a time in my java-script adventure where I have needed to nest callbacks. 我已经来过我的java脚本冒险,我需要嵌套回调。 I have the following code. 我有以下代码。 I keep reading bout nested callbacks being hell... if someone could explain or help with the code. 我继续阅读bout嵌套回调是地狱......如果有人可以解释或帮助代码。 I am still very new to asynchronous programming. 我仍然是异步编程的新手。 I am using nodejs , express 3.0 , jade , node-mysql 我使用的是nodejsexpress 3.0jadenode-mysql

db_helper.getCategory(function (category) {
    db_helper.getCities(function (cities) {
             res.render('/search', category: category, cities: cities });

    });
});

i apologize for not really asking. 我为没有真正要求而道歉。 Im wondering if this is ok to do this? 我想知道这是否可以做到这一点? Whats a better way to handle nested callbacks? 什么是处理嵌套回调的更好方法?

Take a look at the async npm module. 看一下异步 npm模块。 It helps with organizing callbacks and avoiding the deep nesting you are referring to. 它有助于组织回调并避免您所指的深度嵌套。 Perhaps the waterfall would help. 也许瀑布会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM