Yan Yi
Posts: 0
Joined: Sat Jan 25, 2014 7:38 pm

Using objects in Local Storage, services and database collection

Hello!

I have some functions which take objects as arguments and returns the modified object.

Also need to store the object in Appery database and use createService and updateService to create and update the object.

My questions:

  1. Should I set collection column to string or object? If object, is this format correct?
    code {"mon":[],"tue":[],"wed":[],"thu":[],"fri":[],"sat":[],"sun":[]} /code

  2. I have some problems using JSON.stringify to store object in local storage (see code below)
    codevar op_hours = {

    "mon": [],
    "tue": [],
    "wed": [],
    "thu": [],
    "fri": [],
    "sat": [],
    "sun": []
    };

    localStorage.setItem('_ophoursArr', JSON.stringify(op_hours));
    /code
    This gives error Uncaught TypeError: undefined is not a function at appery.js:1752
    line 1752: newValue = value.replace(this.paramPattern, __performHeaderParametersSubstitution);

    JSON.stringify is successfully executed and the value stored into Local storage, but then the error appears.

  3. How to use a local storage value to set createService or updateService, if the requested value is to be an object? I can only use strings in LSV and thus can only send strings as request values.

    Thank you!

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Using objects in Local Storage, services and database collection

Hi Yan,
ol
li It depends on your collection field type.

If your field type is string - you should return string. codereturn '{hello: "world"}';/code

If your field type is object - you should return object. code{hello: "world"}/code/li

Yes, your mentioned object is correct.

liWe have tested your code - and it's ok. No error has been appeared.

So you have error in other code. You should find it and figure it out./li

liYou should convert the string (recieved from LSV) into the object.

For this purpose you should use "JSON.parse". See following code:
precode

var LSVString = localStorage.getItem("_ophoursArr");

var object = JSON.parse(LSVString);/code/pre/li
Regards./ol

Return to “Issues”