John5269257
Posts: 0
Joined: Mon Jun 17, 2013 11:04 am

computing list fields

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

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

computing list fields

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

John5269257
Posts: 0
Joined: Mon Jun 17, 2013 11:04 am

computing list fields

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

John5269257
Posts: 0
Joined: Mon Jun 17, 2013 11:04 am

computing list fields

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.

John5269257
Posts: 0
Joined: Mon Jun 17, 2013 11:04 am

computing list fields

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

computing list fields

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.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

computing list fields

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.

John5269257
Posts: 0
Joined: Mon Jun 17, 2013 11:04 am

computing list fields

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

computing list fields

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

John5269257
Posts: 0
Joined: Mon Jun 17, 2013 11:04 am

computing list fields

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

Return to “Issues”