Objects and Arrays

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    Objects and Arrays

    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 "aPhaseCode s" 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;Cont ract Drilling Services;1110"
    1
    "1099_92;1110_1 0;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"
    Code:
    [INDENT]var aTemplates = new Object();[/INDENT]
    
    		var dDept = new Array();
    		dDept[dDept.length] = string2Array(aPhaseCodes[0].substring(0,4));
    
    		for (var i = 0; i < aPhaseCodes.length; i++ )
    		{
    
    			var pCode = aPhaseCodes[i].substring(5,7);
    
    			if (dDept == aPhaseCodes[i].substring(0,4))
    			{
    				dDept[dDept.length] = {value:pCode, text:pCode};
    			}else{
    				aTemplates[dDept] = dDept;
    				dDept.length = 0;
    				dDept = string2Array( aPhaseCodes[i].substring(0,4) );
    				dDept[dDept.length] = {value:pCode, text:pCode};
    			}
    		}
    function xPC(value, text)
    {
    	this.value = value
    	this.text = text
    }
    function string2Array(string) {
        eval("var result = " + string);
        return result;
    }
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    #2
    Originally posted by Claus Mygind
    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 "aPhaseCode s" 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;Cont ract Drilling Services;1110"
    1
    "1099_92;1110_1 0;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"
    Code:
    [INDENT]var aTemplates = new Object();[/INDENT]
    
    		var dDept = new Array();
    		dDept[dDept.length] = string2Array(aPhaseCodes[0].substring(0,4));
    
    		for (var i = 0; i < aPhaseCodes.length; i++ )
    		{
    
    			var pCode = aPhaseCodes[i].substring(5,7);
    
    			if (dDept == aPhaseCodes[i].substring(0,4))
    			{
    				dDept[dDept.length] = {value:pCode, text:pCode};
    			}else{
    				aTemplates[dDept] = dDept;
    				dDept.length = 0;
    				dDept = string2Array( aPhaseCodes[i].substring(0,4) );
    				dDept[dDept.length] = {value:pCode, text:pCode};
    			}
    		}
    function xPC(value, text)
    {
    	this.value = value
    	this.text = text
    }
    function string2Array(string) {
        eval("var result = " + string);
        return result;
    }
    I solved this problem.

    Comment

    Working...