Вопрос

I am trying to save trips to the server, so I am trying to create 2 scope variables at the same time but unassigned_requests aren't being filtered.

This is in my controller:

$.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)); 
});

And my service contains this:

// 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
Это было полезно?

Решение

You're assigning a function to your unassigned_requests instead of performing actual filtering.

I think you need this:

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)); 
});
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top