Hi ppl. Thanks for any help. I change my code and now it works
perfectly. I'm now saving the json structure in another way, like
this:
array["timestamp"] = timestamp_now;
array["destination"] = typed_text;
instead of
array["timestamp"] = typed_text;
so now it works perfectly, thanks :D
On Jun 20, 9:51 am, Samuka <[EMAIL PROTECTED]> wrote:
> Hi the difference between "destination" and "destino" vars was a
> typing error :D When I was posting this issue I tried to "translate" a
> bit the code :D But in my code both vars are named "destino", so this
> was not the issue. Consider both to be "destino", ok?
>
> So, I'll try to explain the problem again, ok?
>
> The first time an user types something into his text box, the code
> will save that value in this form:
>
> ///////////// var arrayofvalues[timestamp_of_now] =
> typed_code_input_box;
> ///////////// var json = gadgets.json.stringify(salvarDestino);
>
> so, in a json structure, we would have something like this, right?:
> ///////////// {
> ///////////// timestamp_of_now : typed_code_input_box,
> ///////////// }
>
> when I save it like this:
>
> /////////////
> req.add(req.newUpdatePersonAppDataRequest(opensocial.DataRequest.PersonId.VIEWER,
> 'ownerDestino', json));
>
> i would have something like this, in the server-json structure:
>
> ///////////// {
> ///////////// XXXXXXUSERIDXXXXXXX : { ownerDestino :
> { timestamp_of_now : typed_code_input_box, } },
> ///////////// }
>
> right?
>
> so, when the user types something else, to change the value, I want
> the data strucuture to be like this:
>
> ///////////// {
> ///////////// XXXXXXUSERIDXXXXXXX : { ownerDestino :
> { new_timestamp_of_now : new_typed_code_input_box, } },
> ///////////// }
>
> So, the older value should be erased. Hhowever, i'm getting something
> like this:
>
> {
> XXXXXXUSERIDXXXXXXX : { ownerDestino : {
>
> timestamp_of_now : typed_code_input_box,
>
> new_timestamp_of_now : new_typed_code_input_box,
> } },
>
> }
>
> or maybe this:
>
> {
> XXXXXXUSERIDXXXXXXX : { ownerDestino : { timestamp_of_now :
> typed_code_input_box, } },
> XXXXXXUSERIDXXXXXXX : { ownerDestino : { new_timestamp_of_now :
> new_typed_code_input_box, } },
>
> }
>
> So, I want the older value to be cleared, and only the new one to be
> saved. I Thought my script would do this, because, tecnically, it
> would overrite the entire 'ownerDestino' key! However, I'm always
> getting more than 1 result when I fetch the values.
>
> So, this is it, can you help me ?
>
> thanks,
> Samuel Brandão
>
> On Jun 19, 5:57 pm, "Arne Roomann-Kurrik (Google)"
>
> <[EMAIL PROTECTED]> wrote:
> > I see a slight problem where you're assigning the value of the input
> > to a variable named "destination" and then referring to it later as
> > "destino".
>
> > I modified your code a bit to write and read the value of the data you
> > are storing. You should see an alert box containing a json string
> > representing your data, with the timestamp changing after each
> > request:
>
> > var destino = "Test value"
> > var dia = new Date().getTime();
>
> > var salvarDestino = {};
> > salvarDestino[dia] = destino;
> > var json = gadgets.json.stringify(salvarDestino);
>
> > var req = opensocial.newDataRequest();
> > req.add(req.newUpdatePersonAppDataRequest(
> > opensocial.DataRequest.PersonId.VIEWER,
> > 'ownerDestino',
> > json));
> > req.add(req.newFetchPersonAppDataRequest(
> > opensocial.DataRequest.PersonId.OWNER,
> > 'ownerDestino'), "retrieve");
> > req.add(req.newFetchPersonRequest(
> > opensocial.DataRequest.PersonId.OWNER), "me");
> > req.send(response);
>
> > function response(data) {
> > var me = data.get("me").getData();
> > var myData = data.get("retrieve").getData()[me.getId()]
> > ["ownerDestino"];
> > alert(gadgets.util.unescapeString(myData));
>
> > };
>
> > You can gadgets.json.parse() this string to get access to a
> > corresponding object.
>
> > Hope this helps,
> > ~Arne
>
> > On Jun 18, 12:37 pm, Samuka <[EMAIL PROTECTED]> wrote:
>
> > > Hi everybody. I have a script like this:
>
> > > /////////////////////////////////////////////////////////////////
> > > // get text value typed from a form
> > > var destination = document.getElementById('input_destino').value;
> > > // display loading message
> > > document.getElementById('block01').innerHTML = "Loading ...";
> > > var dia = timestamp;
>
> > > /* prepare an array to be save do persistent data. The array index
> > > will be a timestamp value loaded from an external server (php file).
> > > The value is the typed text (var destino) */
>
> > > salvarDestino[dia] = destino;
> > > var json = gadgets.json.stringify(salvarDestino);
>
> > > //* make the request for saving */
> > > var req = opensocial.newDataRequest();
>
> > > req.add(req.newUpdatePersonAppDataRequest(opensocial.DataRequest.PersonId.VIEWER,
> > > 'ownerDestino', json));
> > > req.send(request);
> > > /////////////////////////////////////////////////////////////////
>
> > > As you can see, I save an array with the name "ownerDestino".
> > > Everytime the user clicks an "ok" button, it will save this array,
> > > with a different timestamp as an index. So, the container should
> > > always erase any previous value, and save this array with only one
> > > timestamp index with 1 value, no matter what index, right?
>
> > > However, when i fetch this information and loop the returned array, it
> > > always shows previous values, without erasing them. Can you help me?
>
> > > I have already tried to change the last part of the code, but anyway
> > > it still shows the previous values:
> > > //* make the request for saving */
> > > var req = opensocial.newDataRequest();
>
> > > req.add(req.newUpdatePersonAppDataRequest(opensocial.DataRequest.PersonId.VIEWER,
> > > 'ownerDestino', null));
>
> > > req.add(req.newUpdatePersonAppDataRequest(opensocial.DataRequest.PersonId.VIEWER,
> > > 'ownerDestino', json));
> > > req.send(request);
>
> > > so i tried, in the same request, setting 'ownerDestino' to null, and
> > > then saving, but won't work
>
> > > any ideas?
>
> > > thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"OpenSocial Application Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/opensocial-api?hl=en
-~----------~----~----~----~------~----~------~--~---