【发布时间】:2017-02-04 18:31:57
【问题描述】:
我有一个返回公司列表和用户列表的 php api, 每个用户都有一个 company_id 分配。
(用户:CustomerList)(公司:CompanyList)
这些公司有一个 company_id 和 company_name 值。
我正在使用 resolve 来获取这两个数组。
显示 CustomerList 时,显示客户的 company_id 并且一切正常。
但我需要的不是显示 company_id,而是显示在 CustomerList 中的 company_name。
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;
})
查看
<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。
提前感谢您的帮助。
【问题讨论】:
标签: javascript php html angularjs angular-ui-router