Page 3 of 5
save to db
Posted: Wed Mar 27, 2013 4:37 pm
by Kateryna Grynko
Hi Michael,
In Database, "addresses" column has type = "array". You're trying to save string there.
You should convert the data to array in mapping.In front of Request parameter "addresses" click "Add JS" and paste the following code:codereturn [value];/code
The value selected in Select Menu will be saved in Database.
save to db
Posted: Wed Mar 27, 2013 5:12 pm
by Michael4771079
Thanks Katya,
something working
i have added the js,
in db,user test, addresses result is ["London","New Yourk","Rome"]
when I save addresses to other user the result is
[""]
save to db
Posted: Wed Mar 27, 2013 6:12 pm
by Kateryna Grynko
Michael,
The user with correct values was created by our devs. An empty value [""] was saved after empty value was selected in addressselectmenu.
If you want to save in database an array of created favourite adresses, you should in mapping, in front of Request parameter "addresses" replace the JS that I adviced with the following JavaScript code that will get addresses data from the localStorage variable:
codereturn JSON.parse(localStorage.getItem("variable_name"));/code
save to db
Posted: Wed Mar 27, 2013 6:49 pm
by Michael4771079
Cheers Katya,
thats brill, works very well
the last bit is this
how do I get all the users details to load to localstorage from db on login?
thanks for all your help, you, all at tiggzi are the best support there is!
save to db
Posted: Wed Mar 27, 2013 7:33 pm
by Kateryna Grynko
To get all the users details to load to localstorage from db on login you should create Rest Service with the following parameters:
codeURL: {database_url}/users/{object_id}
Method: GET
Settings: choose database settings from the dropdown list./code
In Request parameters should be:
codeX-Tiggzi-Database-Id = {database_id}
X-Tiggzi-Session-Token
object_id/code
Response parameters should be like the following:
Such service can be used to get user data from database. Request parameter object_id should be mapped to localStorage variable "userId".
save to db
Posted: Wed Mar 27, 2013 8:39 pm
by Michael4771079
Hi Katya,
sorry about this,
I have done the above, and exported ipa, but the db info is not on phone,i.e addresses,name,email and mobile, all components are empty,
when I login on phone successfully I am taken to settings screen,
on load I have invoked the service,
do I need more mapping to make this work?
save to db
Posted: Wed Mar 27, 2013 9:48 pm
by Kateryna Grynko
You save addresses to database. Do you restore these addresses when logging in?
You should map response parameter "addresses" to localStorage variable used in app.
save to db
Posted: Thu Mar 28, 2013 4:19 pm
by Michael4771079
Hi Katya,
the variable used for addresses is "variable_name" I can see it in the dom but
this variable is not in the mapping screen to enable me to map to it from the db,
sorry about this I'm having a blonde one!
save to db
Posted: Thu Mar 28, 2013 7:08 pm
by Kateryna Grynko
Michael,
If there is no "variable_name" variable in mapping interface then you have to add it. This won't break existing variables and code.
After adding you can use this variable in mapping.
save to db
Posted: Thu Mar 28, 2013 8:15 pm
by Michael4771079
Katya,
I not getting this,
I have added the variable,created the service as per you advice, but no result, I maybe looking at this for to long, not seeing my mistake,