javascript - Grab the first item in jQuery Template array -


i have array sizes can access in jquery template. however, in scenario array have 1 item , i'd access directly. how can jquery templates?

this attempt not work:

<input type="hidden" name="product_id" data-related-product-id="${$index}" value="${sizes[0]}${product_id}" />

and outputs this:

<input type="hidden" value="[object object]{product_id}" data-related-product-id="1" name="product_id">

i can't seem find documentation on how this.

this output json.stringify on sizes.

[{"product_id":"51507322000","free_stock":"0","size":"000xs","title":"xs","sizes_group_id":"29,33","oos_status":"0","dept":"51","slug":"this-is-the-slug","sizes_group":{"29":{"id":"29","title":"xs","position":"20","type_title":"clothing","depts_to_include":",01,15,11,31,32,21,22,23,24,42,41,51,61,13,29,45,46,35,55,28,26,20,33,19,14,16,25,27,18,17,65,98,","depts_to_exclude":",81,85,"}},"product_url":"https://crmpicco.dev/p/this-is-the-slug/"},{"product_id":"51507322001","free_stock":"4","size":"001s","title":"s","sizes_group_id":"30,34","oos_status":"0","dept":"51","slug":"this-is-the-slug","sizes_group":{"30":{"id":"30","title":"s","position":"21","type_title":"clothing","depts_to_include":",01,15,11,31,32,21,22,23,24,42,41,51,61,13,29,45,46,35,55,28,26,20,33,19,14,16,25,27,18,17,65,98,","depts_to_exclude":",81,85,"}},"product_url":"https://crmpicco.dev/p/this-is-the-slug/"},{"product_id":"51507322002","free_stock":"4","size":"002m","title":"m","sizes_group_id":"31,36","oos_status":"0","dept":"51","slug":"this-is-the-slug","sizes_group":{"31":{"id":"31","title":"m","position":"22","type_title":"clothing","depts_to_include":",01,15,11,31,32,21,22,23,24,42,41,51,61,13,29,45,46,35,55,28,26,20,33,19,14,16,25,27,18,17,65,98,","depts_to_exclude":",81,85,"}},"product_url":"https://crmpicco.dev/p/this-is-the-slug/"},{"product_id":"51507322003","free_stock":"9","size":"003l","title":"l","sizes_group_id":"32,38","oos_status":"0","dept":"51","slug":"this-is-the-slug","sizes_group":{"32":{"id":"32","title":"l","position":"23","type_title":"clothing","depts_to_include":",01,15,11,31,32,21,22,23,24,42,41,51,61,13,29,45,46,35,55,28,26,20,33,19,14,16,25,27,18,17,65,98,","depts_to_exclude":",81,85,"}},"product_url":"https://crmpicco.dev/p/this-is-the-slug/"},{"product_id":"51507322004","free_stock":"4","size":"004xl","title":"xl","sizes_group_id":"35,40","oos_status":"0","dept":"51","slug":"this-is-the-slug","sizes_group":{"35":{"id":"35","title":"xl","position":"24","type_title":"clothing","depts_to_include":",01,15,11,31,32,21,22,23,24,42,41,51,61,13,29,45,46,35,55,28,26,20,33,19,14,16,25,27,18,17,65,98,","depts_to_exclude":",81,85,"}},"product_url":"https://crmpicco.dev/p/this-is-the-slug/"},{"product_id":"51507322005","free_stock":"2","size":"005xxl","title":"xxl","sizes_group_id":"46","oos_status":"0","dept":"51","slug":"this-is-the-slug","sizes_group":{"46":{"id":"46","title":"xxl","position":"25","type_title":"clothing","depts_to_include":",01,15,11,31,32,21,22,23,24,42,41,51,61,13,29,45,46,35,55,28,26,20,33,19,14,16,25,27,18,17,65,98,","depts_to_exclude":",81,85,"}},"product_url":"https://crmpicco.dev/p/this-is-the-slug/"}]

based on size array structure, have this: ${sizes['somethinghere'][0]}.

you can use json.stringify(sizes) dump , see whatever [object object] contains.

edit:

replace ${sizes[0]}${product_id} ${sizes[0]['product_id']} in code. should first element in array (or element if there one).


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -