Hi Viniclus,
You can save several figures into a key by concatenating them together
into a string with a delimiter of your choice:
var str = "figure1, figure2, figure3, figure4";
and when recovering it, you need to use JS split function to break it
apart like this:
var pattern = /,/;
result = str.split(pattern);
However, our best practices RECOMMEND that you put all of the values
into a JavaScript object or array and use gadgets.json.stringify to
turn this structure into a JSON encoded string. Then you can simply
pull this string out of persistence, call gadgets.json.parse, and not
worry about the string parsing at all. We have sample persistence
code snippet like this on code.google.com.
Hope this helps!
On Jun 30, 8:41 am, Vinicius <[EMAIL PROTECTED]> wrote:
> I want to add several key figures in a ...
>
> I can give example of code? please!
>
> example: key = (figure 1, figure 2, figure 3, ...)
>
> and then recover these values!
>
> On Jun 30, 3:42 am, "Arne Roomann-Kurrik (Google)"
>
> <[EMAIL PROTECTED]> wrote:
> > I see a lot of JavaScript errors in this code. For example,
> > thefield[thefield.length] will never return anything but undefined
> > since you are indexing past the end of the array. What are you trying
> > to do with this code? It would be easier to debug if you could
> > explain what you're trying to do.
>
> > Thanks,
> > ~Arne
>
> > On Jun 23, 10:37 pm, Vinicius <[EMAIL PROTECTED]> wrote:
>
> > > what is wrong in the code?????? not running this ... I tried this
> > > code ... use array pra register several keys dynamically and their
> > > values , help me plis !!!
>
> > > <script type="text/javascript">
> > > gadgets.util.registerOnLoadHandler(requestData);
>
> > > var htmlout = "";
> > > var me = null;
>
> > > function AddData() {
> > > var req = opensocial.newDataRequest();
> > > var palavras = document.getElementById("input_comm").value;
> > > var thefield = [];
>
> > > req.add(req.newUpdatePersonAppDataRequest("VIEWER",
> > > thefield[thefield.length], palavras));
> > > req.send(requestData);
> > > }
>
> > > function requestData() {
> > > var req = opensocial.newDataRequest();
> > > var fields = [ "thefield" ];
>
> > > req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER),
> > > "viewer");
> > > req.add(req.newFetchPersonAppDataRequest("VIEWER", fields),
> > > "viewer_data");
> > > req.send(handleRequestData);
> > > }
>
> > > function handleRequestData(data) {
> > > var mydata = data.get("viewer_data");
> > > var viewer = data.get("viewer");
> > > me = viewer.getData();
>
> > > if (mydata.hadError()) {
> > > htmlout += data.getError();
> > > return;
> > > }
> > > // Do something with the returned data - note the getData call
> > > doSomethingWithData(mydata.getData());
> > > }
>
> > > function doSomethingWithData(data) {
> > > //Data is indexed by user id, and represents an object where
> > > keys
> > > //correspond with the app data fields.
> > > var mydata = data[me.getId()]["thefield"];
>
> > > document.getElementById('content_div').innerHTML +=
> > > mydata[mydata.length] + "<br />";}
>
> > > </script>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---