Event driven GUI, looping through an array, help

D

delraydog

I have an associative array that I need to loop through, allbills,
however, each element in this array requires processing by the user and
I need to capture the users actions on the element and then return to
the next element in the list but suspend looping until I have the users
desired action...

For example,

for(mybill in allbills)
{
GetWhatToDo(mybill); // gets the information about what user wants to
do with the currentBill
}

The problem is that the function "GetWhatToDo" doesn't "block" so the
loop completes without waiting for the users input from GetWhatToDo...

So, my thought was I need to design things more 'event-driven' and
handle things like so:

function handleABill() {
mybill=GetNextBill();
GetWhatToDo(mybill);
}

A "Next" button inside the popup generated by GetWhatToDo will have an
onclick event that calls handleABill again...

The problem is that I can't figure out how to write GetNextBill so that
it maintains the state of the loop through 'allbills', especially since
'allbills' is an associative array and I can't keep track of the array
index. The only thing I can think of is to initialize a regular array
from the associative array and keep track of the index number.

Any other ideas?

Cliff.

http://www.websitenotify.com
 
V

VK

The only thing I can think of is to initialize a regular array
from the associative array and keep track of the index number.

Universally that seems as the best way. You can also re-iterate
through the object properties every time until you find the
current property and then return the next one:

function returnNext(current) {
var gocha = false;
for (var p in allbills) {
if (gocha) {
return p;
}
else if (p == current) {
gocha = true;
}
else {
// NOP
}
}
}

....but with a lot of properties it gets uneffective (and ugly from the
very start :)

JScript has Enumerator wrapper to create an navigable associative
array:
var aaAllBills = new Enumerator(allbills)
with fixable pointer and methods atEnd, item, moveFirst, moveNext
Method

JScript also has Dictionary constructor to create full-qualified
associative
array a la Perl.

But what JScript has - it doesn't help too much to other UA's :-(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top