Page 1 of 2

computing list fields

Posted: Mon Jun 17, 2013 11:16 am
by John5269257

Good morning
I'm populating a list with a service, I need to do some calculations based on data returned in each record.

Example:

For each record returned by the service I have:
label1 mapped to responseParameter1
label2 mapped to responseParameter2

so my results go:
record 1:
label1: "foo"
label2: "bar"

record 2:
label1: "big"
label2: "small"

This works.
I need for each record to have label3, which is the result of a calculation involving labels 1 and 2. For example, with simple concatenation:

record 1:
label1: "foo"
label2: "bar"
label3: "foobar" < computed

record 2:
label1: "big"
label2: "small"
label3: "bigsmall" < computed

Is there a way of doing this that takes advantage of appery's inbuilt looping?
(Mapping both parameters to a single label seems allowed by the UI, but I dont know how to access the values in javascript).

Thanks for your help,
John


computing list fields

Posted: Mon Jun 17, 2013 12:53 pm
by Maryna Brodina

Map to Label both values and JS for Label:
codereturn element&#46;text() + value;/code


computing list fields

Posted: Mon Jun 17, 2013 1:45 pm
by John5269257

Thanks Marina

I'm working with a pre-defined service - in the ContentList I need to compare Title and Filename, and if they are the same, remove the filename extension and display it. If they aren't the same, display the title.

I can do the manipulation, I just don't see how i can reference each field.

My mapping below : - I've mapped "Title" and Filename to "test"

Thanks again, John

Image


computing list fields

Posted: Mon Jun 17, 2013 3:10 pm
by John5269257

Sorry for duplicated entries - a problem with single quotes mangled my first post, which I tried to delete. On that thread (https://getsatisfaction.com/apperyio/...) you requested a screenshot of my mapping, which is above.


computing list fields

Posted: Mon Jun 17, 2013 4:31 pm
by John5269257

Thanks Marina -
I actually need to do more than concatenate - is it documented anywhere how to manipulate multiple mappings to one label? - your example works, but I need to compare two values and act accordingly, and I can't figure out how to identify each value
John


computing list fields

Posted: Mon Jun 17, 2013 4:50 pm
by Kateryna Grynko

Hi John,

You would need to use Success or Complete event.

Success receives full data in the first parameter.

In the first parameter Complete receives jqXHR (http://api.jquery.com/Types#jqXHR) where you can also find server response.

You would need to do all the calculations there.


computing list fields

Posted: Mon Jun 17, 2013 5:01 pm
by Kateryna Grynko

The system doesn't provide this. That is, you can try to map multiple values ​​to the same item, but the choice of value is not a predictable behavior. In particular, you do not know with what value JS-code for this element in mapping will be called.


computing list fields

Posted: Thu Jul 04, 2013 10:45 am
by John5269257

Katya - could I impose upon you to provide a simple example of how to receive and parse the jqXHR using javascript in appery?

I think others might find it useful too :)

John


computing list fields

Posted: Thu Jul 04, 2013 4:10 pm
by Kateryna Grynko

Hi John,

REST Service has 3 events: Success, Complete, Error.
Appery.io executes AJAX requests via jQuery.ajax(); (http://api.jquery.com/jQuery.ajax/).

As in jQuery.ajax(); the following parameters are sent to event handler:
code
&#47;&#47; Error
&#47;&#47; Type: Function( jqXHR jqXHR, String textStatus, String errorThrown )
var data = arguments[0],
textStatus = arguments[1],
jqXHR = arguments[2];

&#47;&#47; Success
&#47;&#47; Type: Function( PlainObject data, String textStatus, jqXHR jqXHR )
var data = arguments[0],
textStatus = arguments[1],
jqXHR = arguments[2];

&#47;&#47; Complete
&#47;&#47; Type: Function( jqXHR jqXHR, String textStatus )
var jqXHR = arguments[0],
textStatus = arguments[1];/code


computing list fields

Posted: Thu Jul 04, 2013 8:58 pm
by John5269257

I've added your success code to the success event of a service in appery, and I'm wading through the console.logged data. A useful start, thanks