0

Please look at the picture below and help me

I want to do something like this:

a busy cat

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.

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)?

Please explain me with examples

I hope I have expressed my question carefully.
thank you

mas cm
  • 131
  • 2
  • 10

1 Answers1

1

The callback function is called when the upload is complete.

Put the call to Book.update inside it.


If you want to avoid nesting, the use Promises and see Removing Nested Promises

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • how to access a local variable(in this case global_d) from within nested callback functions(in this case part A)? – mas cm Feb 11 '18 at 12:00
  • The variable will still be in scope for the nested function. Just use its name. – Quentin Feb 11 '18 at 12:02
  • But I do the same But the result is undefined!! – mas cm Feb 11 '18 at 12:04
  • 1
    Then your function is changing it to `undefined`, because you explicitly set its initial value to `null`. Presumably, your real code (represented by the comment "//myuploadedpicname" in the question) is wrong. – Quentin Feb 11 '18 at 12:05