By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,485 Members | 1,031 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,485 IT Pros & Developers. It's quick & easy.

Objects and Arrays

Claus Mygind
100+
P: 571
This is driving me buggy. but I cannot get a returned string from an ajax call to associative array (hash table)

The returned string from the ajax call has two sets of data wish I split into an array with one data set in each row of the "aCombined" array.

From there I split each of the data sets into separate arrays. In this case the "aPhaseCodes" array holds the data I which to manipulate (see below)

I wish to build an array of objects from which I can dynamically create a listbox populated with the data returned in the aPhaseCodes array.



Sample data:

aCombined
0
"72755;Contract Drilling Services;1110"
1
"1099_92;1110_10;1199_30;5080_80"
aPhaseCodes
0
"1099_92"
1
"1110_10"
2
"1199_30"
3
"5080_80"
----------------------------------
Desired Output

oPhaseCoder
Object 1099=Object 1110=Object 1199=Object 5080=Object
1099
Object
0
Object text=92
text
"92"
value
"92"
1110
Object
0
Object text=10
text
"10"
value
"10"
Expand|Select|Wrap|Line Numbers
  1. var aTemplates = new Object();
            var dDept = new Array();
  2.         dDept[dDept.length] = string2Array(aPhaseCodes[0].substring(0,4));
  3.  
  4.         for (var i = 0; i < aPhaseCodes.length; i++ )
  5.         {
  6.  
  7.             var pCode = aPhaseCodes[i].substring(5,7);
  8.  
  9.             if (dDept == aPhaseCodes[i].substring(0,4))
  10.             {
  11.                 dDept[dDept.length] = {value:pCode, text:pCode};
  12.             }else{
  13.                 aTemplates[dDept] = dDept;
  14.                 dDept.length = 0;
  15.                 dDept = string2Array( aPhaseCodes[i].substring(0,4) );
  16.                 dDept[dDept.length] = {value:pCode, text:pCode};
  17.             }
  18.         }
  19. function xPC(value, text)
  20. {
  21.     this.value = value
  22.     this.text = text
  23. }
  24. function string2Array(string) {
  25.     eval("var result = " + string);
  26.     return result;
  27. }
  28.  
  29.  
Nov 24 '08 #1
Share this Question
Share on Google+
1 Reply


Claus Mygind
100+
P: 571
@Claus Mygind
I solved this problem.
Nov 24 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.