Page 1 of 1

Passing multiple values to a single label

Posted: Sun Mar 17, 2013 11:23 pm
by Jonathan Clark

I'm trying to figure out how to take the value from two different fields, perform calculations on them and then return the value of those calculations. I have a response that returns an array of fields. Two of the fields contain location cordinates (one field for lat, one field for long).

What I want is to pass both of these values to a single label element, run them through a function that gets a saved set of coordinates from local storage, and the returns the distance between the two sets. I have a working function to perform the calculations but I just can't figure out how to access the values when passing two fields to a page element. Any advice?


Passing multiple values to a single label

Posted: Mon Mar 18, 2013 2:59 am
by maxkatz

I hope I understand the question correctly, but you can read values from a Label component using:

code
Tiggzi('component_name').text();
/code

More info on JS API http://docs.tiggzi.com/javascript-api/


Passing multiple values to a single label

Posted: Fri Mar 22, 2013 2:35 pm
by Jonathan Clark

I suppose that does help a little and I think for what I am trying to accomplish I could add two additional labels that are not visible to just hold the value momentarily.

Just to clarify on my original question:

I receive a response from the DB that is an array of records, and there are two specific fields in each array that I want to use in a function that then produces the value that I want to display on the page. I don't really want either of the two values from the response to be displayed. (The two values are lat,long cords that I then want to run through a function that calculates the distance between the returned lat,long and the users lat,long)

As I'm typing this, It's just occurred to me that maybe I should re-format the response so that each record array contains another array which contains the lat and long fields, and then pass that actual inner array ($) to the label?
Would that then pass the array to the javascript function as the value variable?


Passing multiple values to a single label

Posted: Fri Mar 22, 2013 4:08 pm
by Maryna Brodina

Hello! You can redefine the response, but from Label it won't be passed as an array, but as the string. If this string is a correct json object then you can parse it using JSON.parse