KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
How would you get the value of assocIMG by key matching the key eg if I have a var 11786 I want it to return media/catalog/product/8795139_633.jpg var spConfig = { "attributes": { "125": { "id": "125", "code": "pos_colours", "label": "Colour", "options": [{ "id": "236", "label": "Dazzling Blue", "price": "0", "oldPrice": "0", "products": ["11148"] }, { "id": "305", "label": "Vintage Brown", "price": "0", "oldPrice": "0", "products": ["11786", "11787", "11788", "11789", "11790", "11791", "11792", "11793"] }] } } }; var assocIMG = // Added - Removed { here, causes issues with other scripts when not working with a configurable product. { 11786: 'media/catalog/product/8795139_633.jpg', 11787: 'media/catalog/product/8795139_633.jpg', } Above is the objects I am working with and below is my current jQuery. Help would be greatly appreciated. $('#attribute125').change(function() { var image = $(this).val(); $.each(spConfig.attributes, function() { prods = $(this.options).filter( function() { return this.id == image; } )[0].products[0]; alert(prods); }); });
Tags (comma-separated)
Save Edits
Cancel