2014-05-09 6 views
-1

여행을 서버에 저장하려고 했으므로 동시에 2 개의 범위 변수를 만들려고했으나 unassigned_requests가 필터링되지 않았습니다.AngularJS : 범위 필터가 작동하지 않습니다.

$.when(SharePointJSOMService.getRequests()) 
    .done(function(jsonObject){ 
     $scope.requests = jsonObject.d.results; 

     $scope.unassigned_requests = function(){ 
      return $scope.requests.filter(function(el){ 
      return el.Assigned_To === ''; 
      }); 
     }; 
    $scope.$apply(); 
}).fail(function(err){ 
    console.info(JSON.stringify(err)); 
}); 

그리고 내 서비스이 포함되어 있습니다 :

이 내 컨트롤러에

// GET DIVISIONS 
    this.getDivisions = function(){ 
     var deferred = $.Deferred(); 

     JSRequest.EnsureSetup(); 
     hostweburl = decodeURIComponent(JSRequest.QueryString["SPHostUrl"]); 
     appweburl = decodeURIComponent(JSRequest.QueryString["SPAppWebUrl"]); 

     var executor = new SP.RequestExecutor(appweburl); 
     executor.executeAsync({ 
      url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists/GetByTitle('ITI_DIVISIONS')/items?$select=id,Title&@target='" + hostweburl + "'", 
      method: "GET", 
      headers: { "Accept": "application/json; odata=verbose" }, 
      success: function(data, textStatus, xhr){ 
       deferred.resolve(JSON.parse(data.body)); 
      }, 
      error: function(xhr, textStatus, errorThrown){ 
       deferred.reject(JSON.stringify(xhr)); 
      } 
     }); 
     return deferred; 
    }; // /getDivisions 

답변

0

당신은 기능을 할당하고하는 unassigned_requests대신 실제 필터링을 수행. 오류

function filterRequest(requests){ 
    return requests.filter(function(el){ 
     return el.Assigned_To === ''; 
    }); 
} 

$.when(SharePointJSOMService.getRequests()) 
    .done(function(jsonObject){ 
     $scope.requests = jsonObject.d.results; 
     $scope.unassigned_requests = filterRequest($scope.requests); 
     //or $scope.unassigned_requests = $scope.requests.filter(function(el){ 
     //          return el.Assigned_To === ''; 
     //         }); 
     $scope.$apply(); 
}).fail(function(err){ 
    console.info(JSON.stringify(err)); 
}); 
+0

: 'filterRequest는' – jgravois

+0

@jgravois을 정의되지 않는다 :

난 당신이 필요하다고 생각하면'filterRequest' 기능을 선언 했습니까? 그러나 IMP는이 경우에는'$ scope.requests.filter'를 직접 사용합니다. –

+0

아직 그 중 하나를 배운하지 않았습니다 – jgravois

관련 문제