Page 1 of 1

set image asset source when populating a list

Posted: Tue Jul 14, 2015 12:19 am
by Carl Ott

I have a REST service which returns an arbitrary number of items which I'll use to populate a list item.

I need to show a unique image based on an identifier for each item in the REST response, and am trying to select the image with JavaScript in the Mapping Action Editor. In other words, for each unique identifier, I need to set the image source for the corresponding list item image.

I've tried all sorts of things - this code seems closest - but I'm still missing something:

function (value, element) {

switch (value) {
case 'case1':
element.attr('src', 'files/views/assets/image/image1.png').show();
break;
case 'case2':
element.attr('src', 'files/views/assets/image/image2.jpg').show();
break;
}

I even found this old reference to a very similar sounding problem,
https://getsatisfaction.com/apperyio/...

but still couldn't get it from there.

Please help :)


set image asset source when populating a list

Posted: Tue Jul 14, 2015 3:43 pm
by Pavel Zarudniy

Hi Carl,
Unfortunately it is not clear enough.
What types of item do you mapping?
Could you please provide more details, screen shots would also help.


set image asset source when populating a list

Posted: Tue Jul 14, 2015 7:26 pm
by Carl Ott

sure

I'm convinced this is just an object referencing problem - I have this kind of UI

Image

after running the REST service in Echo mode, you can see the list item iterates properly and loads labels properly, but I clearly haven't referenced the image sources correctly

Image

this is the sample response data which feeds the list items

Image

this is how response data is mapped to the list item elements

Image

with JavaScript that clearly needs some magic correction

Image

and my feeble attempt to figure out the bad referencing issues by logging stuff to the console

Image

which (after drilling down) shows the currentSrc attribute having the wrong value

Image

so it seems that I've isolated the problem, but I haven't been able to find the correction yet...

surely this is just a JS newbie issue; I greatly appreciate any help :)


set image asset source when populating a list

Posted: Tue Jul 14, 2015 7:54 pm
by Carl Ott

Opps - never mind - I finally figured it out.

correcting the JavaScript to this

Image

yields this

Image