Angular - ng-repeat不能与搜索控制器一起使用

时间:2016-08-16 15:57:12

标签: javascript jquery angularjs

我有一个我正在使用的搜索控制器:

boolean hasMobile = false;
boolean hasHome = false;
boolean hasWork = false;

while (pCur.moveToNext()) {
    int phoneType = pCur.getInt(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));
    String phoneNumber = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

    if(phoneType == TYPE_MOBILE){
        holder.mNumberMoBilePhone.setText(phoneNumber);
        holder.mNumberMoBilePhone.setVisibility(View.VISIBLE);
        holder.textMobilePhone.setVisibility(View.VISIBLE);
        hasMobile = true;
    }else if(phoneType == TYPE_HOME){
        holder.mNumberHomePhone.setText(phoneNumber);
        holder.mNumberHomePhone.setVisibility(View.VISIBLE);
        holder.textHomePhone.setVisibility(View.VISIBLE);
        hasHome = true;
    }else if(phoneType == TYPE_WORK){
        holder.mNumberWorkPhone.setText(phoneNumber);
        holder.mNumberWorkPhone.setVisibility(View.VISIBLE);
        holder.textWorkPhone.setVisibility(View.VISIBLE);
        hasWork = true;
    }
}

if(!hasMobile) {
    holder.mNumberMobilePhone.setVisibility(View.GONE);
    holder.textMobilePhone.setVisibility(View.GONE);
}

if(!hasHome) {
    holder.mNumberHomePhone.setVisibility(View.GONE);
    holder.textHomePhone.setVisibility(View.GONE);
}

if(!hasWork) {
    holder.mNumberWorkPhone.setVisibility(View.GONE);
    holder.textWorkPhone.setVisibility(View.GONE);
}

这是HTML:

function searchRes($scope, $http, API, CarDetailService, $state){

  $scope.$watch('search', function() {
    fetch();
  });

  $scope.currentPage = 1;
  $scope.pageSize = 5;

  function fetch(){
    $http.get(API + "/search/" + $scope.search)
    .then(function(response){ 
      $scope.details = response.data;
    });
  }

  $scope.select = function(){
    this.setSelectionRange(0, this.value.length);
  }

  $scope.selectCar = function(carId) {
    CarDetailService.setCar(carId);
    $state.go('taskDetails');
  };

}

我试过了:

<div ng-controller="searchRes" class="mainSearch">

  <div class="searchBar">
    <input type="text" ng-model="search" onclick="select()" placeholder="Enter Search Term" autofocus />
  </div>

  <div ng-repeat="res in details.Search">
    <div>{{ res['Display Name'] }}</div>
  </div>

</div>

以下是API返回的图像(data.Results):

enter image description here

当我执行console.log(响应)时,

编辑;我可以看到返回的所有JSON数据(data.Results)

我知道我显然没有正确地调用数据,但我不知道还有什么可以尝试的,我想这就是我在这里的原因。

1 个答案:

答案 0 :(得分:3)

您需要ng-repeat="res in details.Results"