Created
April 1, 2017 06:30
-
-
Save sdjcw/af8e469f8b594cb297d786b75b17488d to your computer and use it in GitHub Desktop.
LeanCloud JS-SDK 遍历表
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const forEachAVObject = (query, fn) => { | |
let cursor = new Date(0); | |
const innerFn = () => { | |
return query | |
.greaterThan('createdAt', cursor) | |
.ascending('createdAt') | |
.limit(1000) | |
.find() | |
.then((objs) => { | |
_.forEach(objs, fn); | |
if (objs.length === 1000) { | |
cursor = _.last(objs).get('createdAt'); | |
return innerFn(); | |
} | |
}); | |
}; | |
return innerFn(); | |
}; | |
// example: | |
forEachAVObject(new AV.Query('Todo').equalTo('author', 'zhangsan'), (todo) => { | |
console.log('>>', todo); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
大部分这种场景都是要修改对象然后写回数据库的,确保所有操作顺序执行会比较好。
这样就可以做批量修改: