Because i have to have some of the data in memory so that i can do a search, for example by name, since the API doesn't allow it...
On Feb 27, 3:28 pm, Paul Lindner <lind...@inuus.com> wrote: > Instead why not use opensocial.DataRequest.PeopleRequestFields.FIRST > and opensocial.DataRequest.PeopleRequestFields.MAX to do limit/offset > type of operations. > > You can get the total number of records by calling getTotalSize() on > the resulting collection > > http://wiki.opensocial.org/index.php?title=Opensocial.Collection_%28v... > > On Feb 27, 2009, at 7:18 AM, Robson Dantas wrote: > > > Hi Pedro. > > > You have to build an algorithm to make it work like you want. I´ve > > cut a piece of code that makes something like you want. I didnt test > > it, but probably will work. > > > Take a look and if you have any questions, send a message again. > > > // global vars > > var NUM_RECORDS=16; > > var page=0; > > var numberFriends=0; > > > function loadFriends() { > > > var req = opensocial.newDataRequest(); > > var opt_params = { }; > > opt_params[opensocial.DataRequest.PeopleRequestFields.MAX] = 400; > > opt_params[opensocial.DataRequest.PeopleRequestFields.FILTER] = > > opensocial.DataRequest.FilterType.HAS_APP; > > > req > > .add > > (req > > .newFetchPeopleRequest > > (opensocial.DataRequest.Group.OWNER_FRIENDS,opt_params), > > 'viewerFriends'); > > > req.send(onLoadFriends); > > > } > > > /** > > * Callback to receive friends > > */ > > function onLoadFriends(data) > > { > > > var viewerFriends = data.get('viewerFriends').getData(); > > > i=1; > > firstRecord = (page*NUM_RECORDS)+1; > > numberPages = 0; > > > try{ > > viewerFriends.each(function(person) { > > > if(i>=firstRecord && i < (firstRecord+NUM_RECORDS)){ > > // handle your operations here > > } > > > i++; > > } > > }); > > > // fix pagination > > i--; > > > // total number of friends > > numberFriends = i; > > > // number of pages > > numberPages = i/NUM_RECORDS; > > > // fix number of pages > > if(numberPages % NUM_RECORDS > 0 && numberPages > NUM_RECORDS) > > numberPages++; > > > // convert it to integer > > numberPages = parseInt(numberPages); > > > // just to call pages to test. > > document.write('<input type="button" value=">" > > onclick="javascript:move('+page+'+1)"'+(page+1>=numPag ? ' > > disabled':'')+'>'); > > document.write('<input type="button" value="<" > > onclick="javascript:move('+page+'-1)"'+(page<=0 ? ' disabled' : '') > > +'>'); > > > } > > > /* > > * Simple function to move between pages > > */ > > function move(pageNumber) > > { > > // assign to global variable > > page = pageNumber; > > > //load friends again > > loadFriends(); > > } > > > Cheers, > > > -Robson > > > You just need to use that and make a loop to iterate > > 2009/2/27 Pedro Vicente <neteinst...@gmail.com> > > > Oh and i forgot. The nasty thing is that if i store like the first 50 > > friends, and have 10 per page, then every time i change page and try > > to get the data, i will loop through the first 10, ou 20, or.. i get > > the picture. > > > On Feb 27, 2:33 pm, Pedro Vicente <neteinst...@gmail.com> wrote: > > > I knew that way, but thought that there was a "nicer" or "cleaner" > > > way. > > > > Tks > > > > On Feb 27, 2:26 pm, Robson Dantas <biu.dan...@gmail.com> wrote: > > > > > Hi Pedro. > > > > > The simplest way is to use a variable to count first five and > > then exit. > > > > > var i=1; > > > > xpto.each(function(person){ > > > > > if (i==5) return; > > > > > do stuff.. > > > > > i++; > > > > > }); > > > > > Let me know if it is what you want. > > > > > Cheers, > > > > > --Robson Dantashttp://blogdodantas.dxs.com.br > > > > > 2009/2/27 Pedro Vicente <neteinst...@gmail.com> > > > > > > Hello, > > > > > > I've been looking at some examples of apps in hi5 and > > OpenSocial page. > > > > > > All of them make a request of 10 friends for example, and then > > with > > > > > the xpto.each(function(person) { .... use them all. > > > > > > My question is, how do i get only the 5 first friends of the > > 10 (so > > > > > that i can request a X ammount of friends and do some pages > > with them > > > > > without having to do a cycle with all of them... > > > > > > Thanks in advanced and sorry if the is a more javascript > > question. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "OpenSocial Application Development" group. To post to this group, send email to opensocial-api@googlegroups.com To unsubscribe from this group, send email to opensocial-api+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/opensocial-api?hl=en -~----------~----~----~----~------~----~------~--~---