Google Datastore でページネーションを行うのに問題があります。制限なしで数百の結果を持つクエリがあります。ユーザーがさらに必要な場合は、次の 5 を取得します。
ドキュメントに従って、クエリを作成します。
var query = datastore.createQuery('ResultsKind').filter('name', 'bobby').limit(5).autoPaginate(false);
次に、次のクエリを実行して、最初の 5 つの結果を取得します。
datastore.runQuery(query, callback);
これはコールバック関数です:
function callback(err, entities, nextQuery, apiResponse) {
if (err) {
// An error occurred while running the query.
console.log('err ' + err);
return;
}
if (nextQuery) {
console.log('res = ' + entities);
datastore.runQuery(nextQuery, callback);
} else {
// No more results exist.
console.log('no more results');
return;
}
};
問題はres =、コンソールに結果が表示されずに無限に印刷されることです。何が間違っているのかわかりません。私がしたいことはです。
1) I create the initial query.
2) I run the query.
3) I get the first 5 results.
4) I pass these results + the nextquery object to the user.
5) If the user wants more results the pass me back the nextQuery and I run this query and get the next 5 results and so on.
私はこのドキュメントを見てきました: http://googlecloudplatform.github.io/gcloud-node/#/docs/v0.30.2/datastore/query?method=autoPaginate。
この単純なページネーションをどのように達成できますか?