我在使用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。
如何完成这个简单的分页?