Results 1 to 2 of 2
  1.    #1  
    So in a model.jsjsjs $file$ $I$ $am$ $creating$ $a$ $structure$:

    Code:
    var Things = Class.create
     ({
    	AllThings: [{
    	ThingA: 
    	[
    		{
    			right: "right",
    			wrong:"wrong"
    		},
    		{
    			right: "yes", 
    			wrong:"no"
    		},
    		{
    			right: "yup", 
    			wrong:"down"
    		}
    	]},
    	{ThingB:	
    	[
    		{
    			right: "go", 
    			wrong:"stop"
    		},
    		{
    			right: "jump", 
    			wrong:"sit"
    		}
    	]
    }]
    	,
    	// initialize - Assign default data to the feedlist
    	initialize: function() {
    		this. getThings();
    	},
    	getThings: function() {
    		var returnList = [];
    		for (var i=0; i< this.AllThings.length; i++) {
    			returnList[i] = this.AllThings[i];
    		}
    		return returnList;
    	}
    });
    
    this.things = new Things();
    If I put that in a jsjsjs $file$, $have$ $prototype$ $on$ $the$ $same$ $page$ $when$ $I$ $try$ $to$ $access$ $this$.$things$ $I$ $see$ $the$ $data$ $in$ $Firebug$. $My$ $problem$ $is$ $how$ $to$ $manipulate$ $that$ $data$. $I$ $guess$ $I$ $never$ $have$ $done$ $much$ $with$ $JSON$, $but$ $if$ $I$ $want$ $to$ $drill$ $down$ $into$ $the$ $right$ $and$ $wrong$ $key$/$value$ $pairs$, $i$ $have$ $to$ $be$ $explicit$.

    Code:
    for (int i = 0; i < this.things.AllThings.ThingA.length; i++) {
     var test = this.things.AllThings.ThingA[0].right;
    }
    Just to get anything out, what I really want to do is iterate through AllThings without having to specify ThingA explicitly afterward, something like...
    Code:
    for (int j = 0; j < this.things.AllThings.length; j++) {
     var test = this.things.AllThings[0];
    }
    Where if I inspect test it would have the contents of ThingA on the first loop and ThingB on the second loop...

    I can't believe I can't figure this out, I must be looking at it from the wrong angle or something. Hopefully this is basics I am overlooking.
  2. #2  
    Well, what you've created is a weird quasi-multi-dimensional array.
    So Allthings[0] contains thingA and thingB arrays.

    Using your last bit of code

    for (int j = 0; j < this.things.AllThings.length; j++) {
    for( int i=0; i<AllThings[j].ThingA.length; i++ )
    something = ThingA[i];
    for( int k=0; i<AllThings[j].ThingB.length; k++ )
    something = ThingB[k];
    }

    See what I mean?
    WOG Dev - WebOS Group http://www.WebOSGroup.com
    PMP Dev - http://www.PimpMyPre.com
    Apps: WOG O.S.K., WOG Card Keeper, WOG Glowstick, WOG Kid Protect, PreLoad, PimpMySounds

Posting Permissions