我有兩個模式,一個用於醫生信息,另一個用於排名。 我的醫生架構:從兩個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