Page 1 of 1

display substring of a service response

Posted: Tue Sep 16, 2014 4:30 pm
by Mathias Uebelacker

Hei all,

i stuck at format the content of a label in a better readable form. The situation is:

I show the datas of a service response in a grid. The mapping of the values to the columns works fine. And now i will do some lift up to make things easier for the user. So the actual text for example 7.43789567 should be cut after 7.43. In this case 2 digit after the dot is okay no math needed to round in a mathematical correct way. I tried parseInt, substring and parseFloat as advised from Katya but all i get is nothing or NaN.

So please if anyone could provide a script sample which i could use in js area of the response mapping instead of try pasrseFloat that would be great. I tried different things over the last two days and it seems that i take a look only from one point of view.

Thanks
Mathias


display substring of a service response

Posted: Tue Sep 16, 2014 5:17 pm
by Evgene Karachevtsev

Hello Mathias,

Could you please show an example of response (to understand what you have there - a number or a string)?


display substring of a service response

Posted: Tue Sep 16, 2014 5:29 pm
by Mathias Uebelacker

Good evening Evgene,

the original values are stored at parse.com :-) sorry, I created a service according to your docs, retrieve the values and map them to a label (text) in a list item placed in a grid. So i think the actual format is text but i am not familiar with your mapping process. and thats seems to be my prob. I do not know exactly how the mapping will be handled and how to use js in the edit js area in your mapping feature. So just summarized original in parse.com number, get it with your parse.com rest integration and mapping the response to a label within a list item within a grid.

Thanks for your help
br
Mathias


display substring of a service response

Posted: Tue Sep 16, 2014 11:58 pm
by Yurii Orishchuk

Hi Mathias,

I guess Evgene asked you to show whole response (you can make screen shot in browser debug network tab for corresponding request).

Anyway here is solution for you based on unknown field data type.

1 Click "Add JS" on corresponding field. http://prntscr.com/4njcwo/direct

2 Populate it with following JS code:

pre

//Get string.
var stringValue = String(value).trim();

console.log("stringValue = " + stringValue);

//Get float value.
var floatValue = parseFloat(stringValue);

console.log("floatValue = " + floatValue);

//Convert float value.
var convertedValue = Math.round(floatValue * 100) / 100;

console.log("convertedValue = " + convertedValue);

return convertedValue;

/pre

Note: i've added to this code some debug information. You need to delete this console.log lines when you get it works.

Regards.