MSFN Forum: Dynamic JSON arrays - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Dynamic JSON arrays in JavaScript Rate Topic: -----

#1 User is offline   mritter 

  • WPI Co-Developer
  • Group: Developers
  • Posts: 1,090
  • Joined: 13-November 05

Posted 07 October 2010 - 08:02 PM

I am building a dynamic database in JSON with a JavaScript HTA. I am stuck on "visualizing" how to traverse the array.

The easiest way I can explain this in something everyone knows is an email program's Inbox folders. You start out with an empty folder, all the new messages go in it. Fine.

Now, the user wants to add a sub-folder, Mark, and sub-folder Work. Fine, I can do that. Building it is easy.

Inbox
---Mark (folder)
---Work (folder)
.....messages in Inbox root not in a sub-folder....

Now the user is going crazy:

Inbox
---Mark (folder)
---Work (folder)
------Accounting (folder)
------Shipping (folder)
---------National (folder)
---------International (folder)


This is all fine if I make the JSON array "hardcoded" from the start so I would know how to access it:

Inbox[1].Work[1].Shipping[0].National[0].Message1

BUT, it was created by the user, so how do I step through the dynamically created JSON database not knowing the names (per se) and the depth of the array?

Essentially, I need a JavaScript database that will traverse the array for me looking for the ID (or whatever tag) I give it:

var message=jsonDB.find("ID","f7df68yfudsaf67fd");
or
var message=jsonDB.find("From","eat@joes.com");

That returns an object pointing to that email message, in which I can do:

message.From="eat@joes.com";
message.To="bugs@bunny.com";


The same issue above also carries over to deleting the email message, deleting entire folders, etc.
var message=jsonDB.delete("ID","87hds732h");


I looked at TaffyDB but what I tried didn't work. It doesn't seem to like nested arrays.

This post has been edited by mritter: 07 October 2010 - 08:04 PM



#2 User is offline   geezery 

  • Member
  • PipPip
  • Group: Members
  • Posts: 254
  • Joined: 21-July 06

Posted 12 January 2011 - 04:11 PM

View Postmritter, on 07 October 2010 - 08:02 PM, said:

I am building a dynamic database in JSON with a JavaScript HTA. I am stuck on "visualizing" how to traverse the array.

The easiest way I can explain this in something everyone knows is an email program's Inbox folders. You start out with an empty folder, all the new messages go in it. Fine.

Now, the user wants to add a sub-folder, Mark, and sub-folder Work. Fine, I can do that. Building it is easy.

Inbox
---Mark (folder)
---Work (folder)
.....messages in Inbox root not in a sub-folder....

Now the user is going crazy:

Inbox
---Mark (folder)
---Work (folder)
------Accounting (folder)
------Shipping (folder)
---------National (folder)
---------International (folder)


This is all fine if I make the JSON array "hardcoded" from the start so I would know how to access it:

Inbox[1].Work[1].Shipping[0].National[0].Message1

BUT, it was created by the user, so how do I step through the dynamically created JSON database not knowing the names (per se) and the depth of the array?

Essentially, I need a JavaScript database that will traverse the array for me looking for the ID (or whatever tag) I give it:

var message=jsonDB.find("ID","f7df68yfudsaf67fd");
or
var message=jsonDB.find("From","eat@joes.com");

That returns an object pointing to that email message, in which I can do:

message.From="eat@joes.com";
message.To="bugs@bunny.com";


The same issue above also carries over to deleting the email message, deleting entire folders, etc.
var message=jsonDB.delete("ID","87hds732h");


I looked at TaffyDB but what I tried didn't work. It doesn't seem to like nested arrays.


Maybe you could try the solution from here, then you would not need to know the propery names:

http://efreedom.com/...Item-Array-JSON

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy