我有两个模式,一个用于医生信息,另一个用于排名。 我的医生架构:从两个http req获取数据并将它们合并
var doctorsSchema = new schema({
Entity: {type:String},
name: {type:String},
Expertise : {type:String},
HMO: {type:String},
Address: {type:String},
reception_hours: [],
lat: {type:Number},
lng: {type:Number},
Ranking : {type:Number}
},{collection: 'doctorsLocation'});
我的排名模式是:
var calSchema = new schema({
Entity: {type:String},
name: {type:String},
Expertise : {type:String},
Address: {type:String},
Attention : {type:Number},
Professional: {type:Number},
Availability: {type:Number},
Atmosphere: {type:Number},
Recommendation: {type:Number}
},{collection: 'cal'});
我要计算每个医生的排名和后打印每个医生在屏幕上的所有细节。
这是我的控制器(在angularjs):
mymedical.controller('calCtrl',['$scope','$http','$cookies', function($scope,$http,$cookies){
var generalInfo = Array();
$http.get('http://localhost:3000/doctors').then(function(response){
//console.log(response);
var generalData = response.data;
for(var i=0; i<generalData.length; i++){
$http.post('http://localhost:3000/calculateRanking',generalData).then(function(res){
//console.log(res.data);
var info ={};
info.Ranking = res.data;
//console.log(res.data);
console.log("1");
info.Entity = generalData[i].Entity;
info.name = generalData[i].name;
info.Expertise = generalData[i].Expertise;
info.Address = generalData[i].Address;
info.reception_hours=generalData[i].reception_hours;
info.HMO=generalData[i].HMO;
generalInfo.push(info);
}).then(last(generalInfo));
}
//info.Ranking = 0;
//console.log(rank);
});
function last(val)
{
$scope.general = val;
//console.log(generalInfo);
console.log("last");
}
}]);
我把所有服务器端所有的医生,然后, 我有一个计算的服务器端(node.js的)分级功能 功能根据每位医生得到calSchema并计算他们的排名并发回客户端(控制器)的排名。 我得到的排名后,我想显示我所有的数据到屏幕上, 但我有角度同步问题,它打印我所有的医生,并在打印排名后,我想一起打印它们, 我需要什么要解决它吗?
感谢,
它看起来像医生的整个阵列上运行的功能被发送到 “calculateRanking” API。这发生在每个医生身上。你的意思是一次只派一名医生到医院吗? –
是的,这正是我的意思 – adi