我有一个php api,返回公司列表和用户列表, 每个用户都有一个company_id分配。获取相关数组元素AngularJS
(用户:CustomerList)(单位:CompanyList)
该公司有COMPANY_ID和COMPANY_NAME值。
我正在使用解析来获得这两个数组。
显示CustomerList时,会显示客户的company_id,并且一切正常。
但我需要的是,而不是显示的company_id,我需要company_name显示在CustomerList中。
CustomerList的company_id与CompanyList中的id相关。
只是company_name包含在companyList中而不包含在CustomerList中。但是ID是相关的并且包含在userList中。
我需要获取CustomerList中的id的company_name并将其显示在视图中。
resolve: { userList:function($http,$stateParams){
return $http.post('/api/get_users.php',{role:$stateParams.role},{headers: { 'Content-Type': 'application/x-www-form-urlencoded' }})
.then(function(response){
console.log(response);
return response.data.data;
})
},
companyList:function($http,$stateParams){
return $http.get('/api/get_companies.php')
.then(function(response){
console.log(response);
return response.data.data;
})
}
}
controller("CustomerList", function($scope,$location,$http,$stateParams,userList,companyList){
$scope.customers = userList;
$scope.companies = companyList;
})
VIEW
<table>
<thead>
<tr>
<th>Username</th>
<th>Company Name</th>
<th>Contact Name</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="customer in customers">
<td>{{ customer.username }}</td>
<td>{{ customer.company_id }}</td>
<td>{{ customer.contact_name }}</td>
</tr>
</tbody>
</table>
的customer.company_id是关系到在companyList的ID,我需要返回companyList.company_name而不是显示在客户对本公司的ID。
在此先感谢您的帮助。
这正是我一直在寻找,再加上还有详细的,完美的。 –