无法使用angular.js从表中过滤某些值

时间:2015-10-03 09:08:06

标签: javascript php angularjs filter

我在我的表中使用了一些罗马值(i.e-I,II,III,......VIII),但是当尝试使用这些值过滤表的某些值时,过滤过程正在发生,并且对于某些值,使用angular.js不会发生这种情况。请检查下面的代码。

  

subject.html:

<table class="table table-bordered table-striped table-hover" id="dataTable" >
<colgroup>
<col class="col-md-1 col-sm-1">
<col class="col-md-2 col-sm-2">
<col class="col-md-2 col-sm-2">
<col class="col-md-2 col-sm-2">
<col class="col-md-2 col-sm-2">
<col class="col-md-2 col-sm-2">
<col class="col-md-1 col-sm-1">
</colgroup>
<thead>
<tr>
<th>Sl. No</th>
<th>
<select style="width:100%; border:none; font-weight:bold;" ng-options="sub.name for sub in noCourse track by sub.value" ng-model="search" ng-change="selectedCourseTable();" >
<!-- <option value="">Course Name</option>-->
</select>
</th>
<th>
<select style="width:100%; border:none; font-weight:bold;" ng-options="sem.name for sem in noSemestersTable track by sem.value" ng-model="semesterSearch">
<option value="">Semester</option>
</select>
</th>
<th>Subject Name</th>
<th>Short Name</th>
<th>Edit</th>
</tr>
</thead>

<tbody id="detailsstockid">
<tr ng-repeat="sub in subjectData | filter:{course_name:search.value, semester:semesterSearch.value }" >
<td>{{ $index+1 }}</td>
<td>{{sub.course_name}}</td>
<td>{{sub.semester}}</td>
<td>{{sub.subject_name}}</td>
<td >{{sub.short_name}}</td>
<td>
<a href='#subject?s_i={{sub.subject_id}}'>
<input type='button' class='btn btn-xs btn-green' value='Edit'>  
</a>
</td>
</tr>   
</tbody>
</table>

为了在表中动态绑定数据,我有一些数据库操作,在数据库中也存储了罗马值。检查我的控制器文件。

  

subjectController.js:

$http({
        method: 'GET',
        url: "php/subject/readCourse.php",
    }).then(function successCallback(response) {
        angular.forEach(response.data, function(obj){
            var Course={'name':obj.course_name , 'value':obj.course_name};
            $scope.noCourse.push(Course);
        });
    },function errorCallback(response) {

    });
$scope.selectedCourseTable=function(){
        if($scope.search.value=='Bachelor of Technology'){
            $scope.noSemestersTable=[
            {name:"I",value: "I"},
            {name:"II",value:"II"},
            {name:"III",value: "III"},
            {name:"IV",value: "IV"},
            {name:"V",value:"V"},
            {name:"VI",value: "VI"},
            {name:"VII",value:"VII"},
            {name:"VIII",value:"VIII"}
            ];
        }
        if($scope.search.value=='Master in Technology'){
            $scope.noSemestersTable=[
            {name:"I",value: "I"},
            {name:"II",value: "II"},
            {name:"III",value:"III"},
            {name:"IV",value:"IV"}
            ];
        }
        if($scope.search.value=='Master of computer application'){
            $scope.noSemestersTable=[
            {name:"I",value:"I"},
            {name:"II",value: "II"},
            {name:"III",value:"III"},
            {name:"IV",value:"IV"},
            {name:"V",value:"V"},
            {name:"VI",value:"VI"}
            ];
        }
        if($scope.search.value==''){
            $scope.noSemestersTable=null;
        }
    }

当我选择值III时,过滤正在正常进行,但是当我从下拉列表中选择I or II时没有发生,所有值都显示出来。实际上我对此问题感到困惑某些值过滤器工作正常,但某些值不起作用。请帮我解决此问题。

1 个答案:

答案 0 :(得分:0)

我认为这是filter的工作方式。你现在使用它的方式匹配并不严格。我认为你应该使用sub in subjectData | filter:{course_name:search.value, semester:semesterSearch.value }:true

请注意true末尾的filter值 - 这会使比较严格。