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来一发
var eventproxy = require('eventproxy');
var ep = eventproxy.create();
ep.fail(function (err) {
log.logger.error(err);
});
babyModel.Baby.find({}),count(ep.doneLater('count'));
ep.on('count', function (cnt) {
if (!ctn) {
return ep.emit('results', []);
}
babyModel.Baby.find({}, {}, {
skip : start,
limit : limit,
sort : {
'updateDate' : -1
}
}, ep.done('results'));
});
ep.all('count', 'result', function (cnt, results) {
res.send({
totalCount: cnt,
data: results
});
});