javascript:
var json = {item1: {foo:bar},item2: {foo:bar)}; $('li').click(function() { var liid = $(this).attr('id'); // outputs 'item1' or 'item2' var thefoovalueiwant = json.liid.foo; });
pretty simple. i'm trying value of foo based off id of <li> gets clicked. json.liid.foo looks liid in json, doesn't exist. how json.the-value-of-liid instead of json.liid itself? thanks!
var thefoovalueiwant = json[liid].foo;
Comments
Post a Comment