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
-~----------~----~----~----~------~----~------~--~---