nodejs如何改变嵌套的写法,帮忙修改下面的代码..如果判断业务很多的话,代码都成歪的了..
发布于 12 年前 作者 songbo 6266 次预览 最后一次回复是 12 年前 来自
babyModel.Baby.find({
}).count(function(err, cnt) {
if(cnt) {
babyModel.Baby.find({
}, {}, {
skip : start,
limit : limit,
sort : {
'updateDate' : -1
}
}, function(err, results) {
if(err) {
log.logger.error('babyList find error:' + err);
} else {
res.send({
totalCount : cnt,
data : results
});
}
});
} else {
res.send({
totalCount : 0,
data : ''
});
}
});
5 回复
手动置顶
eventproxy来一发
可以用 when.js 或者promise
async的waterfall,或者把函数提取出来使用闭包在使用的时候生成,就可以消除金字塔了,node金字塔总是一不小心就搭得很高