简体   繁体   English

sails.js和node.js中代码和函数的执行顺序

[英]The order of the execution of codes and functions in sails.js and node.js

Please look at the picture below and help me 请看下面的图片帮我

I want to do something like this: 我想做这样的事情:

忙碌的猫

I want first part A to be fully executed Then run section B, Because in the first part(A) must the file uploaded compeletly to make the uploaded file name assign to global_d variable, i need this variable in part B. 我希望第一部分A被完全执行,然后运行B部分,因为在第一部分(A)中必须完全上传文件以使上载的文件名分配给global_d变量,因此我在B部分中需要此变量。

The next question is how to access a local variable(in this case global_d) from within nested callback functions(in this case part A)? 下一个问题是如何从嵌套回调函数(在本例中为A部分)中访问局部变量(在本例中为global_d)?

Please explain me with examples 请举例说明我

I hope I have expressed my question carefully. 我希望我已经认真表达了我的问题。
thank you 谢谢

The callback function is called when the upload is complete. 上传完成后,将调用回调函数。

Put the call to Book.update inside it. 把呼叫Book.update 里面


If you want to avoid nesting, the use Promises and see Removing Nested Promises 如果要避免嵌套,请使用Promises ,请参阅删除嵌套的Promises。

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

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