Paul King
Posts: 0
Joined: Fri Apr 25, 2014 4:45 am

Set label value for each item in a list

Hi,
I am returning a list of items with latitude and longitude values. I have some javascript which calculates the distance from my current location. I have mapped the response and a couple of other fields which is working as expected.

What I need to do now is trigger that calculation for each location and set a label for each item in the list. I can't work out what coding I need for this or where I need to put it.

I thought I could maybe add it on to the javascript of another field to set the related distance label but it just overwrites the first label in the list each time.

Any help would be appreciated.
Thanks

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Set label value for each item in a list

Hi,

You can add calculation JS code in the service mapping.
http://docs.appery.io/documentation/r...

Paul King
Posts: 0
Joined: Fri Apr 25, 2014 4:45 am

Set label value for each item in a list

Hi, thanks for the reply. I know how to do the calculation I'm just unclear as to how I set each label in the list.

So each response in my list has a lat and lng value. I want to somehow pick these two values up and drop them in to my related distance_label for each list item.

As mentioned above it just overwrites the same label. Do I need to reference an ID somehow? Is this even possible?

Thanks

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Set label value for each item in a list

Hello Paul,

You should map your lat and lng to local storage variable, then "add JS" with your custom calculation code to your "distance_label" as it's stated here: http://docs.appery.io/documentation/r...
In your code you have to get values from local storage variables, make calculation and return calculated value.

Paul King
Posts: 0
Joined: Fri Apr 25, 2014 4:45 am

Set label value for each item in a list

I understand this documentation fine but what I dont understand or see any documentation on is what is mentioned above - 'add JS' to the distance label.

You can't add any javascript unless you map the component to the response. I can't map the response as it is two values, lat and lng.

I'm returning a list of locations with lat and lng, I can map them to local variables but I'm guessing the key element I am missing is as mentioned above, adding javascript to the label itself to set that labels value.

How can you set a label within a list without mapping it with a value from the response?

I appreciate your help with this.

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Set label value for each item in a list

Hello Paul,

You can map the two response parameter in one UI component
https://getsatisfaction.com/apperyio/...

Return to “Issues”