我需要一些指導來確定如何在兩個不同的表中爲角度js創建兩個相似的值。我使用的表格是用戶表格和學校表格。所以我需要做的是基於登錄的用戶,我應該得到一個與該用戶相關的學校名稱,但目前我不知道如何去做這件事。任何幫助指導我如何去做這件事將不勝感激。如何使用angularjs匹配來自兩個不同數據庫的項目
學校服務控制器代碼:
angular.module('starter').factory('Schools',['apiUrl','$resource', 'UserInfo', function(apiUrl,$resource, UserInfo){
var factory = $resource(apiUrl + '/schools/:schoolId',
{
schoolId: '@_id'
}, {
update: {
method: 'GET'
}
});
return factory;
}]);
檔案控制器代碼段:
angular.module('starter.controllers')
.controller('ProfileController', function($scope,$http,$state,Schools, $ionicPopup, apiUrl, UserInfo,$ionicLoading,$ionicHistory,Users,Authentication) {
$scope.apiUrl = apiUrl;
$scope.authentication = Authentication;
$scope.state = $state;
$scope.selected = {};
var user = Authentication.user.school;
$scope.find = function(queryParams){
$scope.place = [];
var user = $scope.authentication.user.school;
var school = Schools.query({_id: user.school})
var params = queryParams || {};
params._id = user;
Schools.query(params, function(response){
if (params._id === school){
// response.splice(0, $scope.place.lengh);
// for(var x = 0; x< response.lengh; x++){
// $scope.place.push(response[x]);
// }
$scope.place = response[0].name;
}
else{
$scope.place = response;
}
})
}
$scope.signOut = function(){
$ionicPopup.confirm({
title: "SIGN OUT",
template: '<p align="center">' + 'PLEASE CONFIRM IF YOU WANT TO SIGN OUT'+ '</p>',
buttons: [
{ text: "NO",
type: 'button button-outline button-assertive',
onTap:function(e){
return false;
}
},
{
text: "YES",
type:'button-positive',
onTap:function(e){
//now you can clear history or goto another state if you need
$ionicHistory.clearHistory();
$ionicHistory.nextViewOptions({ disableBack: true, historyRoot: true });
$state.go('signin');
return true;
}
}
]
});
};
});
我爲「$ scope.find功能」值正常返回,但學校名稱的整個列表和細節而不是與用戶相匹配的細節。
是的,這就是它是如何工作至今。我只是主要與預製控制器進行交互。我還是有點新的角,所以我想了解如何循環我的數據,以查找用戶表詳細信息是否與學校名稱相關的學校表詳細信息,因爲當前用戶表只顯示學校表ID,而不是名字。 –