我有两次递归。有可能将它们重构成一个吗? Requester.update
和Requester.delete
会返回一个承诺,我猜主要问题是他们收到的参数,我不想更改它们。
var tobeDeleted = [];
var tobeUpdated = [];
function calc1(node, original) {
tobeUpdated.push(Requester.update(node["tag_id"], node));
if (node.nodes.length === 0) {
return;
}
_.each(node.nodes, function(x) {
x.hasPublish = original.hasPublish;
x.hasInbox = original.hasInbox;
x.hasMetrics = original.hasMetrics;
calc1(x, original);
});
}
calc1(tag, tag);
function calc2(node) {
tobeDeleted.push(Requester.delete(node["tag_id"]));
if (node.nodes.length === 0) {
return;
}
_.each(node.nodes, function(x) {
calc2(x);
});
}
calc2(tag);