javascript - How to access to dynamic key stored with JQuery data -
i stored info of key value within html element using following:
$('#newitem').data("metadata", data);
this info contains few keys name img0 img1 img2 img3
the number of images not know in advance , i'm getting in key number of images exist in key value data.
i'm trying loop on stored info , pull these value not working:
for ( var = 0; < numofpic; i++ ) { var img = $(item).data("metadata").itempic+i; }
is there way convert itempic+i
key can use?
you can utilize square brackets suggested @hindmost:
var images = $(item).data("metadata"), itempic = 'img'; ( var = 0; < numofpic; i++ ) { var img = images[itempic+i]; // or images["img" + 1] }
and practice run dom search 1 time , cache search instead of doing search every iteration of loop.
javascript jquery
No comments:
Post a Comment