Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
157
rated 0 times [  159] [ 2]  / answers: 1 / hits: 58833  / 13 Years ago, mon, august 1, 2011, 12:00:00

I am writing a webpage with the following structure:




  1. One section (table A) depends on another section (table B);

  2. Another section (table B) has elements that require recalculation on each update. The calculation is handled by external tools, and will cause an event when finished.



In order to guarantee correctness, the table need to be updated only after the other table is fully updated (i.e., done with computation). However, I don't know how to effectively achieve this, and I could not find any wait facility within JavaScript.



For now, I am using the following method:




  1. Declare a global variable updated and make it false;

  2. After the first table received input, I make an empty while loop until updated is true;

  3. Add an listener, once the calculation is done and the event received, set updated to true.



This seems unintuitive to me but I cannot think of any other way of doing it. Is there any good ways to do this?



Thanks for any inputs!


More From » events

 Answers
152

Add an listener, once the calculation is done and the event received, set updated to true.




Instead of setting updated to true, and then waiting for updated to be true- just do whatever you want to do in the listener.



myEventBus.addListener(function () {
// do whatever
updateTable();
alert('table updated!');
});

[#90880] Saturday, July 30, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
josuea

Total Points: 609
Total Questions: 121
Total Answers: 104

Location: South Georgia
Member since Fri, Nov 13, 2020
4 Years ago
josuea questions
;