Create a list based on localStorage array

This forum contains topics that were moved from Get Satisfaction
Jerry Benzie
Posts: 0
Joined: Wed Sep 10, 2014 3:54 pm

Create a list based on localStorage array

Post by Jerry Benzie »

Hello,

This is what I'm trying to do:
Import contacts from native device (which works fine) then add individual contacts to an array in localStorage. Each contact added should then be displayed in a "new" contacts list specific to the mobile app being developed. I basically want to maintain a separate contacts list in the app based on the contacts stored on the device.

This is what I have:
Import contacts from native device works perfectly. Once I select a contact to add to the new contacts list, I only get one contact in the new list. Regardless of how many I continue to select from the imported list. The new list never updates and I don't think the objects I'm selecting to add are being added to the array.

I'm not running any custom JS or anything, I'm merely using mappings within the user interface.

Thank you,
Jerry

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

Create a list based on localStorage array

Post by Kateryna Grynko »

Hi Jerry,

Could you please clarify how you update the second list according to array when adding a contact to a localStorage array?

Please also post a screenshot of mapping?

Jerry Benzie
Posts: 0
Joined: Wed Sep 10, 2014 3:54 pm

Create a list based on localStorage array

Post by Jerry Benzie »

Sure, my apologies for not explaining well enough. Image
When the "Import Contacts" button is pressed, the contacts stored on the native device are shown in the upper-most list container. When a contact (list item) is pressed, it should be saved to an array in localStorage and then shown in the lower list container. This is my first app, so I'm sure I'm doing something wrong, I just don't know where. Below are the screenshots of the mappings.
Image
Image

Thank you for your help,
Jerry

Jerry Benzie
Posts: 0
Joined: Wed Sep 10, 2014 3:54 pm

Create a list based on localStorage array

Post by Jerry Benzie »

Oh, and when a list item in the upper list container is pressed, both the "contacts_toStorage" and "contacts_fromStorage" events are initiated.

Jerry Benzie
Posts: 0
Joined: Wed Sep 10, 2014 3:54 pm

Create a list based on localStorage array

Post by Jerry Benzie »

I'm sure I'm not doing this correctly. Would you be able to explain the best way for accomplishing what I'd like to do?

thank you,
Jerry

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Create a list based on localStorage array

Post by Evgene Karachevtsev »

Hello Jerry,

When you click on a string in the list of contacts from a phone you need to call js code, that will check the array of contacts in LS for duplicate, and if such contact is not already there - add it.
For more information about working with models and LS please look here: http://devcenter.appery.io/documentat...
After the array in the LS is updated, it is necessary to substitute it in echo service which reply is mapped to the second list.
Reply is substitutes like this: http://devcenter.appery.io/documentat...
After echo is set, you should call execute from instance of the service. A common example of echo substitution and instance call is here:
http://take.ms/fkLHz
getContacts.__requestOptions.echo = '[{"phone":"123", "name":"abc"}]';
restservice2.execute();

Jerry Benzie
Posts: 0
Joined: Wed Sep 10, 2014 3:54 pm

Create a list based on localStorage array

Post by Jerry Benzie »

Would the service I need to create be a REST service or a generic service? If it's a REST service, I'm not sure what I need as a URL since I'm only accessing LS?

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Create a list based on localStorage array

Post by Evgene Karachevtsev »

Jerryy,

It is usual REST service, url is no need to be specified. All you should do with it - is specify the mapping and then from the code put echo and call via execute() method.

Jerry Benzie
Posts: 0
Joined: Wed Sep 10, 2014 3:54 pm

Create a list based on localStorage array

Post by Jerry Benzie »

Could you please explain the echo part to me? I apologize for making this so difficult.

Thank you,
Jerry

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

Create a list based on localStorage array

Post by Kateryna Grynko »

Hi Jerry,

Please check this section: http://devcenter.appery.io/documentat...

Post Reply