Roger6240907
Posts: 0
Joined: Mon Sep 16, 2013 5:33 pm

load img from JSON after mapping to Grid

I am mapping a JSON response to a grid. My json returns also a url to load img for each item. Where should I add the code to get the url after the grid is populated, read each image and place it in the right position in the grid?

Thanks
Roger

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

load img from JSON after mapping to Grid

Hello! It depends on data you retrieve and the way you need to upload images. You can add JS in mapping or map URL to hidden field and then on service Success check response and upload images.

Roger6240907
Posts: 0
Joined: Mon Sep 16, 2013 5:33 pm

load img from JSON after mapping to Grid

So here what I tried without success. I added JS to the asset property of the image component. Value contains the image name returned from JSON

function(value,element){
var i=new Image();
i.src='http://example.com/pics/'+value;
return i;
}

If I open a browser to the link I get the correct pics. Any suggestions? All pics are in the jpeg format.

Thanks
Roger

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

load img from JSON after mapping to Grid

If you have image name and you just need to add path to that image - in mapping to image asset add the following code:
codereturn 'http://example.com/pics/'+value;/code

Roger6240907
Posts: 0
Joined: Mon Sep 16, 2013 5:33 pm

load img from JSON after mapping to Grid

Thanks Marina. It works!

Return to “Issues”