我是AngularJS的新手并尝试构建一个小型过滤器应用程序。
代码段:
angular.module('jobs', ['angularUtils.directives.dirPagination'])
.controller('JobsCtrl', ['$scope', '$filter', '$http', function($scope, $filter, $http) {
$scope.qualifications0 = [];
$scope.myPromise = $http
.get('/jobs/jobs_overview.php')
.then(function(response) {
$scope.jobs = response.data;
// we need all kinds of qualifications available
for (var i = 0; i < response.data.length; i++) {
var job = response.data[i];
for (var j = 0; j < job['qualification'].length; j++) {
var qualification = job['qualification'][j];
if (!contains(qualifications, qualification)) {
qualifications.push(qualification);
}
}
}
// add unique qualifications to scope
for (var i = 0; i < qualifications.length; i++) {
var qualification = qualifications[i];
if (qualification.length > 0) {
$scope.qualifications0.push({name:qualification});
}
}
});
...
}]);
&#13;
<?php
$qualification0 = "";
if (isset($_GET['qualification0'])) { $qualification0 = $_GET['qualification0']; }
?>
<div ng-app="jobs">
<div ng-controller="JobsCtrl" class="jobs">
<form class="filter-container row">
...
<select id="qualiselect0" name="qualiselect0" ng-model="qualiselect0" class="qualifications-select">
<option value selected="selected">-- Choose --</option>
<option ng-repeat="qualification in qualifications0" value="{{qualification.name}}">{{qualification.name}}</option>
</select>
...
</form>
...
<tr dir-paginate="job in filtered = (jobs | orderBy:predicate:reverse | multiFilter:{division:[divselect0,divselect1,divselect2],qualification:[qualiselect0,qualiselect1,qualiselect2]} | filter:search ) | itemsPerPage:pageSize | orderBy:predicate" current-page="currentPage" class="repeat-item">
<td>{{job.division}}</td>
<td><a href="" alt="{{job.name}}" ng-click="popup(job.gethtmlurl)" target="_blank">{{job.name}}</a></td>
<td ng-init="job.lastchangedate">{{convertToDate(job.lastchangedate) | date:'dd.MM.yyyy'}}</td>
</tr>
...
</div>
</div>
&#13;
如你所见,我有一个GET参数。这取决于您从哪个页面访问该表。
mywebsite.com/tablesite?qualification=Test
我现在要做的是,如果设置了GET参数,则将其设置为选中并过滤表格。 有没有办法用AngularJS做什么或最有效的方式?