【发布时间】:2017-09-01 18:55:16
【问题描述】:
我在猫鼬中有两个架构,一个用于医生信息,两个用于排名。 我的医生架构:
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。每个医生都在发生这种情况。你的意思是一次只派一名医生去吗?
-
是的,正是我的意思
标签: javascript angularjs node.js mongoose schema