Oto JavaScript wersja bez obietnic ..
Są to zmienne globalne (zbiory nie są wymagane, tylko zły nawyk kopalni) ..
///create a collection of cool things and instantiate it (globally)
var CoolCollection = Parse.Collection.extend({
model: CoolThing
}), coolCollection = new CoolCollection();
Jest to funkcja "zapętlania", która daje wyniki.
//recursive call, initial loopCount is 0 (we haven't looped yet)
function getAllRecords(loopCount){
///set your record limit
var limit = 1000;
///create your eggstra-special query
new Parse.Query(CoolThings)
.limit(limit)
.skip(limit * loopCount) //<-important
.find({
success: function (results) {
if(results.length > 0){
//we do stuff in here like "add items to a collection of cool things"
for(var j=0; j < results.length; j++){
coolCollection.add(results[j]);
}
loopCount++; //<--increment our loop because we are not done
getAllRecords(loopCount); //<--recurse
}
else
{
//our query has run out of steam, this else{} will be called one time only
coolCollection.each(function(coolThing){
//do something awesome with each of your cool things
});
}
},
error: function (error) {
//badness with the find
}
});
}
ten sposób można nazwać (czy można zrobić to inne sposoby):
getAllRecords(0);
Jaka jest wartość początkowa pominięcia? –
Początkowa wartość powinna wynosić 0, jak chcesz zacząć od pierwszego rekordu, i pomiń ten limit, dopóki nie uzyskasz wszystkich obiektów – SquiresSquire
. Aby ten kod zadziałał, musiałem zmienić wartość na globalną. ale axcept dla tego kodu jest warty – itzhar