I think your JSON should be like this:

[
{"Id":1,"Title":"Vacation","HourTypeCodes":[
{"Id":"05","Title":"VACPOLICE/FIRE",},
{"Id":"04","Title":"VACATION"},
{"Id":"62","Title":"VACATION HOURS PURCHASED"},
{"Id":"60","Title":"VACATION SELL BACK"}
]
},
{"Id":2,"Title":"Holiday","HourTypeCodes":[
{"Id":"08","Title":"HOLIDAY"}
]
},
{"Id":3,"Title":"Floating Holiday","HourTypeCodes":[
{"Id":"09","Title":"FLOATING HOLIDAY"}
]
}
]

That would be syntactically correct. However, whether or not it is fit for purpose I am not sure. The top level is an array of objects. What is
"key" when it is retrieved with $(this).prev("input").val(); ?

Is it an array index or is it a value of the "Id" property in each of the objects? If it is the latter, then you don't really have a nice efficient way of getting to the object you want, unless the Id property is always the array index + 1 ?

For example, if "key" contained "1", I would be able to traverse the HourTypeCodes like this:

$.each(jsondata[key-1].HourTypeCodes,function(i,item){ });


-----Original Message-----
From: web400-bounces@xxxxxxxxxxxx [mailto:web400-bounces@xxxxxxxxxxxx] On Behalf Of Kevin Turner
Sent: 15 December 2010 20:01
To: Web Enabling the AS400 / iSeries
Subject: Re: [WEB400] Navigating JSON sub-arrays dynamically

Strange forum for a JSON/jQuery question - but anyhow, the JSON you have posted is syntactically incorrect. Is that just a typo?

Can you post all the significant code please, rather than a snippet, and explain a bit more fully what you are trying to do.

Thanks

-----Original Message-----
From: web400-bounces@xxxxxxxxxxxx [mailto:web400-bounces@xxxxxxxxxxxx] On Behalf Of Mike Wills
Sent: 15 December 2010 19:30
To: Web Enabling the AS400 / iSeries
Subject: [WEB400] Navigating JSON sub-arrays dynamically

I am using JSON and jQuery to dynamically populate a parent/child dropdown
lists. I have it working to fill the parent drop down and have the child
drop down filling with the same parent data. How do I loop through the sub
array of the selected value from the parent?

My "each" line (key is the value from my parent DDL:

var key = $(this).prev("input").val();
$.each(jsondata.Id[key].HourTypeCodes, function(i, item) {

My JSON

[{"Id":1,"Title":"Vacation","HourTypeCodes":[{"Id":"05","Title":"VAC
POLICE/FIRE",},{"Id":"04","Title":"VACATION"},{"Id":"62","Title":"VACATION
HOURS PURCHASED"},{"Id":"60","Title":"VACATION SELL BACK"}]},

{"Id":2,"Title":"Holiday""HourTypeCodes":[{"Id":"08","Title":"HOLIDAY"}]},
{"Id":3,"Title":"Floating
Holiday","HourTypeCodes":[{"Id":"09","Title":"FLOATING HOLIDAY"]}]

What am I doing wrong?

--
Mike Wills
http://mikewills.me
--
This is the Web Enabling the AS400 / iSeries (WEB400) mailing list
To post a message email: WEB400@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/web400
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/web400.


NOTICE: The information in this electronic mail transmission is intended by CoralTree Systems Ltd for the use of the named individuals or entity to which it is directed and may contain information that is privileged or otherwise confidential. If you have received this electronic mail transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email or by telephone, so that the sender's address records can be corrected.



--------------------------------------------------------------------------------


CoralTree Systems Limited
25 Barnes Wallis Road
Segensworth East, Fareham
PO15 5TT

Company Registration Number 5021022.
Registered Office:
12-14 Carlton Place
Southampton, UK
SO15 2EA
VAT Registration Number 834 1020 74.
--
This is the Web Enabling the AS400 / iSeries (WEB400) mailing list
To post a message email: WEB400@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/web400
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/web400.


NOTICE: The information in this electronic mail transmission is intended by CoralTree Systems Ltd for the use of the named individuals or entity to which it is directed and may contain information that is privileged or otherwise confidential. If you have received this electronic mail transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email or by telephone, so that the sender's address records can be corrected.



--------------------------------------------------------------------------------


CoralTree Systems Limited
25 Barnes Wallis Road
Segensworth East, Fareham
PO15 5TT

Company Registration Number 5021022.
Registered Office:
12-14 Carlton Place
Southampton, UK
SO15 2EA
VAT Registration Number 834 1020 74.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.