这是我的代码当前的样子:
var physicianList = [];
function map(doc){
if(doc.PhysicianKey && doc.PhysicianName){
console.log(doc.PhysicianName);
emit(doc.PhysicianKey, doc.PhysicianName);
}
}
dbPhysicianList.query({map: map}, function(error, response){
if(!error){
angular.forEach(response.rows, function(physician){
physicianList.push(physician);
})
deferred.resolve(physicianList);
}else{
console.log(error);
deferred.reject();
}}, {include_docs: true});
return deferred.promise;
}
如您所见,在我的地图函数中,我要注销doc.PhysicianName
,而当我这样做时,它们将按字母顺序注销。但是,physicianList
我认为它们以非字母顺序被推入阵列,按照ID顺序。我希望最终输出在该DoctorList数组中按字母顺序排序。
对于它的价值,我正在使用PouchDB,但我相信查询应该与CouchDB完全一样。
我不知道您变量emit()
的顺序是结果集的顺序(我是一个主要的新手)。
我最终这样做:
function map(doc){
emit({physicianName: doc.PhysicianName, physicianKey: doc.PhysicianKey} );
}
并且它完全按要求工作(按字母顺序排列doc.physicianName
)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句