我在使用 Google Datastore 进行分页时遇到问题。我有一个查询,没有限制,有几百个结果。我想检索 5 个,将它们发送回用户,如果用户想要更多,他们会检索下 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 http://googlecloudplatform.github.io/gcloud-node/#/docs/v0.30.2/datastore/query?method=autoPaginate.
我怎样才能完成这个简单的分页?