Page 1 of 1

More Properties in service mapping?

Posted: Sun May 26, 2013 8:06 pm
by doubletake

In your list examples, you have to replace a list item with a hidden label if you want to pass an ID. This removes the JQueryMobile list item style. (since it is no longer a Li ).

I'd like to pass the studentID in something other than a hidden Label component so I can keep using Li. Are there any other options to do this?

My preference would be able to map the studentID to a "More Properties" item called "data-studentID". But, these additional properties do not show up in the edit mapping view. This way, when the list item is selected, I can set the localStorage using the value of data-studentID.

Thanks,
Don


More Properties in service mapping?

Posted: Sun May 26, 2013 8:45 pm
by Illya Stepanov

Hi - we will try to find a workaround for that. We'll update.


More Properties in service mapping?

Posted: Sun May 26, 2013 9:35 pm
by maxkatz

When you do mapping, you can add JavaScript to it. Two objects are passed to the mapping function: value, element.

'element' - is the jQuery Mobile component to which you are mapping. You could run any code there.

http://docs.appery.io/documentation/a...


More Properties in service mapping?

Posted: Sun May 26, 2013 9:52 pm
by doubletake

Max,
Sorry but I'm not getting how this helps me with my issue?

I need to display the Student Name in the list item, yet also pass in the studentID to the list item.

When the studentName is selected, I need to save the studentID to localStorage for my studentDetails service call.

currently Set Local Storage requires a property of the component to be used.

Maybe I just need to see an example of how map studentID and studentName to the same Li.

Thanks,
Don


More Properties in service mapping?

Posted: Sun May 26, 2013 10:04 pm
by maxkatz

Let's say you added a custom attribute to a list item called "data-studentId". To know which item you clicked on, use Click/Run JavaScript action. You will have access to the current item clicked on. Then find the "data-studentId" attribute in the current (this) node and save it into local storage.


More Properties in service mapping?

Posted: Sun May 26, 2013 10:15 pm
by doubletake

I get that part. However, the service mapping doesn't let me map the studentID value in the result to data-studentID. How do I set this value for each item in the loop?


More Properties in service mapping?

Posted: Sun May 26, 2013 10:19 pm
by maxkatz

In mapping for the collection (root) itself, you could access that JSON response and get any value from it.


More Properties in service mapping?

Posted: Mon Jun 10, 2013 7:34 pm
by doubletake

Max, I got this to work:

In the "loop" mapped list item, I added JS to copy the value object into a custom "data-mydata" property of the current list item element.

$(element).attr('data-mydata',JSON.stringify(value) );
//console.log($(element).attr('data-mydata'));

Then, in the list item click event I grab the object
var o = jQuery.parseJSON( $(this).attr('data-mydata') );

using the data-mydata attr allows me to pass the addition properties I need without having to create a hidden labels, etc. to pass the data in.

I just got used to binding ArrayCollections to lists in Flex and then having access to all the selectedItem's properties.

I guess I just couldn't find the "value" object inside the "element", so I had to copy it there. This works well for me. But, let me know if there is a more efficient way.

Appreciate the help.
Don


More Properties in service mapping?

Posted: Mon Jun 10, 2013 8:30 pm
by maxkatz

This works.