ui-grid过滤不适用于jQUERY

时间:2015-10-16 13:46:55

标签: javascript jquery angularjs

我是棱角分明的新手,我正在尝试使用ui-grid。在我的代码中,当我点击过滤器按钮时,我没有得到数据,我也没有收到任何错误。有人可以帮我吗?这是我的代码:

HTML code:

<input type="button" value="Filter" 
ng-model="filterValue" class="btn  btn-primary"                    
ng-click="applySearchFilter()" />

JavaScript代码:

 $scope.applySearchFilter = function () {         
        assignService.getResult($scope.RequestPrefix, $scope.RequestYear, $scope.RequestNumber, $scope.AssignedToStaff).then(function (assignResult) {
            $scope.assign = assignResult.data;          
            if ($scope.AssignedToStaff == "-1") {            
                $scope.assign = $.grep($scope.assign, function (element, index) {

                return element.AssignStaffId == 0;

               });
            }
        });
    };
$scope.applySearchFilter = function () {
        alert("entering");      // init();
        assignService.getResult($scope.RequestPrefix, $scope.RequestYear, $scope.RequestNumber, $scope.AssignedToStaff).then(function (assignResult) {
            $scope.assign = assignResult.data;
            alert("Result");
            if ($scope.AssignedToStaff == "-1") {
                alert("if condition");
                $scope.assign = $.grep($scope.assign, function (element, index) {
                    alert("staff Data:::" + $scope.assign);
                return element.AssignStaffId == 0;

               });
            }
        });
    };
 <div class="col-md-2">
            <input type="button" value="Filter" ng-model="filterValue" class="btn  btn-primary"
                   ng-click="applySearchFilter()" />
        </div>

1 个答案:

答案 0 :(得分:0)

首先确保assignService.getResult承诺真正解决,尝试添加拒绝回调,以检查承诺是否已解决。

如果承诺得到解决并且您从远程方法获取数据,那么您应该检查ui-grid是否在成功回调中更新了其数据,我想您使用$scope.assign = assignResult.data;来更新ui-grid数据,它看起来没问题,但请确保在你的ui-grid选项中,data属性应该分配一个范围对象名字符串,而不是范围对象:

$scope.uiGridOption = {
    data: 'assign',
    ...other options...
}

$scope.$scope.applySearchFilter = function () {
    assignService.getResult($scope.RequestPrefix, $scope.RequestYear, $scope.RequestNumber, $scope.AssignedToStaff).then(function (assignResult) {
        $scope.assign = assignResult.data;
        alert("Result");
        if ($scope.AssignedToStaff == "-1") {
            alert("if condition");
            $scope.assign = $.grep($scope.assign, function (element, index) {
                alert("staff Data:::" + $scope.assign);
            return element.AssignStaffId == 0;

           });
        }
    });
};