更新时间:2022-10-19 12:55:38
Simply return the promise returned by .then
and either return the final value from the .then
callback, or another promise:
function getParents(bookmark, parents) {
var parents = parents || [];
return getParent(bookmark).then(function(parent) {
parents.push(parent);
return parent.parentId == '0' ? parents : getParents(parent, parents);
});
}
See http://www.html5rocks.com/en/tutorials/es6/promises/#toc-chaining