问题是这样的,我有两组数据存在两个json中,一组叫relationship存了好友关系,(主id,好友id...)
另一组叫user,存了用户信息(id,name,.....),现在我想将好友的id和name都展示出来,一开始
我在controller中先用$http取得relationship的json,然后用ng-repeat列表展示好友id,
但是我不知道怎么通过好友id取得用户信息的name同时展示出来,部分代码如下。
.controller("friendCtrl",function($scope, $ionicPopup,$location,$http) {
$http.get(url).then(function
successCallback(response){
$scope.names = response.data.Relationship;
},function errorCallback(response){
alert("读取错误");
$location.path('/friend');
})
$scope.getName= function(id){
$http.get(url).then(function successCallback(response){
$scope.names1 = response.data.User;
return response.data.User[0].name;
},function errorCallback(response){
alert("读取错误");
$location.path('/friend');
return 0;
})
}
}
<html>
<div class="list">
<label class="item item-input item-stacked-label" ng-repeat="x in names">
<span>{{x.object}}</span>
<span>{{getName(x.object)}}</span>
</label>
</div>
</html>
relationship(subject,object) User(id,name) subject,object都是user中的id
我一开始想{{getName(x.object}},然后写个函数来获取name,但是会引发脏读循环
,而且$http的异步问题不能return数据,请问有什么方法来获得name?