0
我已經完成了this issue,但是,我面臨着應用過濾器奇怪觸發的問題。讓我試着向你解釋。第一個過濾器請求看起來像:以角度網格進行外部過濾的兩次點火
?$orderby=id-&pageSize=25&pageNbr=1&$filter=eventTypeId==7 OPTIONS 200 xhr angular.js:11881 505 B 17 ms
?$orderby=id-&pageSize=25&pageNbr=1&$filter=eventTypeId==7 GET 200 xhr Other 15.3 KB 92 ms
我們有選項,我們得到了,它很好。接下來我們應用第二個過濾器,請求如下所示:
?$orderby=id-&pageSize=25&pageNbr=1&$filter=eventTypeId==7 GET 200 xhr angular.js:11881 15.3 KB 94 ms
?$orderby=id-&pageSize=25&pageNbr=1&$filter=eventTypeId==7;studyId==231 OPTIONS 200 xhr angular.js:11881 505 B 21 ms
?$orderby=id-&pageSize=25&pageNbr=1&$filter=eventTypeId==7;studyId==231 GET 200 xhr Other 15.8 KB 48 ms
?$orderby=id-&pageSize=25&pageNbr=1&$filter=eventTypeId==7 OPTIONS 200 xhr angular.js:11881 505 B 22 ms
由於某種原因,請求激發了兩次。接下來,我們將第三濾波器和請求的樣子:
?$orderby=id-&pageSize=25&pageNbr=1&$filter=eventTypeId==7;studyId==231 OPTIONS 200 xhr angular.js:11881 505 B 18 ms
?$orderby=id-&pageSize=25&pageNbr=1&$filter=eventTypeId==7;studyId==231;statusId==5 OPTIONS 200 xhr angular.js:11881 505 B 19 ms
?$orderby=id-&pageSize=25&pageNbr=1&$filter=eventTypeId==7;studyId==231 GET 200 xhr Other 15.8 KB 43 ms
?$orderby=id-&pageSize=25&pageNbr=1&$filter=eventTypeId==7;studyId==231;statusId==5 GET 200 xhr Other 1.1 KB 27 ms
?$orderby=id-&pageSize=25&pageNbr=1&$filter=eventTypeId==7 GET 200 xhr Other 15.3 KB 95 ms
而且我們可以看到,請求再次發射兩次,但在最後它發送一個僅在第一個過濾器的更多額外的請求。
有人可以向我解釋我的錯誤在哪裏嗎?提前致謝。 我對過濾器代碼:
gridApi.core.on.filterChanged($scope, function() {
// Declare vars
var grid = this.grid;
var columns = grid.columns;
$scope.columnTitle = grid.columns[1].filters[0].term;
$scope.columnDesc = grid.columns[2].filters[0].term;
var columnType = grid.columns[3].filters[0].term;
var columnStudy = grid.columns[4].filters[0].term;
var columnPriority = grid.columns[5].filters[0].term;
var columnSeverity = grid.columns[6].filters[0].term;
var columnStatus = grid.columns[7].filters[0].term;
var columnCreatedDate = grid.columns[8].filters[0].term;
var columnModifiedDate = grid.columns[9].filters[0].term;
// Create request for selectable filters
var query = [];
var string;
function request (id, param) {
if(param === "title==" || param === "description=="){
query.push(param + "*" + id + "*")
} else {
query.push(param + id);
}
if (query.length <= 1){
return query
} else {
string = query.join(";");
return string;
}
}
// Define behavior for cancel filtering
$scope.isfilterclear = true;
angular.forEach(columns, function(col) {
if(col.filters[0].term){
$scope.isfilterclear = false;
}
});
if($scope.isfilterclear) {
$timeout(function() {
$rootScope.refresh()
},500);
}
// Filter behavior for columns
if($scope.columnTitle) {
$scope.$watch('columnTitle', function (newVal, oldVal) {
// filterOptions.filterParam = 'title==*' + newVal + "*";
filterOptions.filterParam = request(newVal, 'title==*');
}, true);
getData()
}
if($scope.columnDesc) {
$scope.$watch('columnDesc', function (newVal, oldVal) {
// filterOptions.filterParam = 'description==*' + newVal + "*";
filterOptions.filterParam = request(newVal, 'description==');
}, true);
getData()
}
if(columnType) {
filterOptions.filterParam = request(columnType, 'eventTypeId==');
getData();
}
if(columnStudy) {
filterOptions.filterParam = request(columnStudy, 'studyId==');
getData();
}
if(columnPriority) {
filterOptions.filterParam = request(columnPriority, 'priorityId==');
getData();
}
if(columnSeverity) {
filterOptions.filterParam = request(columnSeverity, 'severityId==');
getData();
}
if(columnStatus) {
filterOptions.filterParam = request(columnStatus, 'statusId==');
getData();
}
if(columnCreatedDate){
filterOptions.filterParam = request($rootScope.setFilterDate, 'occuredDate>=');
getData()
}
if(columnModifiedDate){
filterOptions.filterParam = request($rootScope.setFilterDate, 'occuredDate>=');
getData()
}
});
哦,閣下!這是顯而易見的,但不是我的頭。謝謝你,兄弟! – antonyboom