我试图节省到服务器的行程,所以我试图同时创建2个范围变量,但unassigned_requests没有被过滤。
这是在我的控制器:
$.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
您正在分配一个功能给您的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));
});