JQuery :: Processing Multidimensional Array With .getJSON
Dec 24, 2010
I have the following (valid) json string:[code]Using firebug, I can see that the GET is returning the entire json string. However, alert only results in one of the two "text" strings being displayed ("and again"). Analyzing the watch/stack window shows that the "json" object resulting from the getJSON call has been reduced to a single "chat" element, instead of both "chat" elements present in the array.
I'm using getJSON to retrieve information from a header record and the corresponding detail records and display the detail records in a table. The PHP script that is called returns a JSON string (via json_encode) that looks like this:
Here is the html table: <table><thead><tr> <th colspan="2" >Item Description</th> <th>Quantity</th> <th>U/M</th> <th>Item Price</th> <th>Item Amount</th> </tr></thead><tbody> <tr class="p_row_1"> .....
And here is the $.getJSON: $.getJSON("GET_INV_INFO.php",{srn:'<?php echo $srn; ?>'},function(s){ // Get Header Info $('#ip_invNo').html(s.jobNo); $('#ip_invDate').html(s.invDate); $('#ip_custNo').html(s.custNo); $('#ip_purchOrd').html(s.purchOrd); $('#ip_custName').html(s.custName); .....
My problem comes in the getJSON section where I'm trying to populate the table with a record. I don't know how to refer to the different fields in array 's'. I've tried the following and many variations, but to no avail: $('.p_row_'+i+':nth-child(1)').html(s.row.i.itemNo); $('.p_row_'+i+':nth-child(1)').html(s.row[i].itemNo); How do I refer to a nested field in a multidimensional array like this?
I am wondering if my code *should* work. I have a php file that reads in images from various folders. It stores the file paths in a javascript array by using echo statements. The array is also defined in the php file, as below, outside of the php tags.
var galleryarray = new Array(); for(var i=0; i < galleryarray.length; i++) {
[code]....
I am getting an error when running the HTML file that says "galleryarray[f1][f2] is undefined". I have another version of this that stores the file paths in a single-dimension array, and this works fine. I am thinking that there could be something wrong with how I am using the multidimensional array in the javascript.
I want a lookup table that matches url fragments to the name I want to show. For instance, if a url contains "yahoo.com", I want to print "Yahoo." For now, I created a multidimensional array that maps url fragments to a name. such as,
So, say I have a variable urlVar, where the value is some URL (for example,[URL]).Is there any way - other than looping through the array for every variable - to check if urlVar contains any of the substrings in urlMapping.urlPath, and if so, output urlMapping.mapto? (In this case, I want urlVar to find that it contains the substring "yahoo.com" and output "Yahoo".) In my code, I anticipate that I have 100 variables checked against 50 mappings, and performance is important to me.
Is there any function or property for finding out the size of the first (or for that matter any) dimension of a multidimensional array?EDIT:There seems to be no such functionality, I found a solution that does not require it. If anyone is reading this for the same reason; it needs to be scripted.
I'm trying to create a multidimensional array (and it's my first time using one) as an easy-to-modify way of populating content into a cycling banner script. However I seem to be having issues with actually accessing the content in the array.So currently my array looks like so:
Code:
<script type="text/javascript"> var banner = new Array(); //Option 1
[code]...
But when I do a "document.write(banner[0]['title']);" in my body, it doesn't seem to want to oblige.
Whats wrong with this code? i decalre resultArray as a new Array(). Then in a for loop for each resultCount i declare resultArray[resultCount] = new Array(). Then i try putting in values for every resultArray[x][y], but when i go to output the array in another function, everything in resultArray is undefined.code...
I have the following code which I am using with Google Maps:
var allLocations = new Array(); function getResults(){ // create the boundary for the data var bounds = map.getBounds();
[Code].....
In short, the resultData is always updating and displaying the correct array and data but the allLocations array outside of of resultData is incorrect and seems one query behind.
I'm trying to use variable variable names using the window[] functionality. It works fine when you literally specify an array's base variable name, but I have a multidimensional array and would like to use window[] to build the name of the specific sub-array I'm looking for, like so:
// here's my multidimensional array myArray = new Array(); myArray['id'] = 'foo'; myArray['sub'] = new Array();
[Code]....
However if temp is the name of a sub-array (e.g. 'myArray[sub]), and not the base array name(i.e. 'myArray'), then window[temp] evaluates to "undefined".
Can the window[] functionality handle this somehow, or do I have to resort to eval() or something else?
I'm trying to use variable variable names using the window[] functionality. It works fine when you literally specify an array's base variable name, but I have a multidimensional array and would like to use window[] to build the name of the specific sub-array I'm looking for, like so:
Code: // here's my multidimensional array myArray = new Array(); myArray['id'] = 'foo'; myArray['sub'] = new Array(); myArray['sub']['id'] = 'bar';
I have an array "arr" that is an array of objects. Each object has the same 7 properties.I want to find the index of the object with a property that matches a certain value x in the array arr. The array has hash tables associated with it.
arr [ obj [ i ] . property1 + "_" + obj [ i ] . property2 ] = arr [ i ] ;
so whats the index of the object where .property1 = x ?
I have an array "arr" that is an array of objects. Each object has the same 7 properties.I want to find the index of the object with a property that matches a certain value x in the array arr. How can i accomplish this?The array has hash tables associated with it.arr [ obj [ i ] . property1 + "_" + obj [ i ] . property2 ] = arr [ i ] ;so whats the index of the object where .property1 = x ?
I'm trying to assign the values from the JSON data returned when I run this code into an array that's outside the callback function. The data is multidimensional, and I have been able to use this data within the callback function. However I want to use it outside that function. i.e. the jsdata returned in the code below is to be used outside the function
Code: $.getJSON('../fxns/status.php',function(jsdata){ //do some stuff with JSON data or pass to global variable[code]..........
HTML Code:I have been trying to figure this out for awhile. I have a multidimensional array in JavaScript that is 12 columns wide and an unknown number of rows like so
<br /> /*<br />[<br /> [userID (int), name, username, email, password, other 1, other 2, other 3, other 4, other 5, other 6, admin(int)],<br />
[code]....
All the values are string except the (int) ones. This is for a real time user editing page for my site. I have the JavaScript array made now I need it so when the "Submit" button is pressed it turns the array formated like that into an PHP array and saves it as a variable.
how would one post a multidimensional array to a php script. The ajax section on here in the docs... only show how you would pass just one array. I need to pass a multidimensional arrays to my php scripts.
I'm kind of new to learning javascript so please consider the following code: orderUser = { products: [ 'Beer', 'Soda', 'Wine' ], users: [], regUser:function(){ varnew_user_id = 12;//normally this wouldn't be a static number ofcourse orderUser.users[orderUser.users.length] = new_user_id; }}
There's an object that has some properties and a method. The method registers an user id to the users property. What I'd like to do next is keep track of what users have ordered. Is this possible with (multidimensional?) properties? Something like userProducts[ 12 ] = [ 1, 0 ] //Soda, Beer doesn't work. Would there be no other way than arrays?
This is my first time using jquery and Ive designed a small and simple fadein/out script that acts as a rollover on this navigation bar: [URL] Here is the code:
It works great. However, if a user quickly moves their mouse over the nav buttons and repeats the process, the rollover affect will fadein/ out over and over again until its completed the cycle the amount of times the user moved the mouse over the button back and forth. I wish to change this behaviour so that, somehow, the processing is aborted if it is noticed the mouse is not present after a fadeout is completed.