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

i am using some Roman value(i.e-I,II,III,......VIII) in my table but when trying to filter table using these value for some value the filtration process is happening and for some value its not happening using angular.js. Please check my code below.

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>

For bind the data dynamically in table i have some db operation and inside the database the Roman values are also stored.Check my controller file.

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;
        }
    }

When i am selecting the value III onward the filtering is occurring properly but when i am selecting I or II from drop down its not happening ,all values are showing.Actually i am confused about this issue for some value filter is working properly but for some value not working.Please help me to resolve this issue.

douzhi9921
douzhi9921 :subjectData是一个包含db值的数组。
大约 5 年之前 回复
du27271
du27271 也许您可以向我们展示subjectData的示例性条目?
大约 5 年之前 回复

1个回答



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

注意末尾的 true </ code>值 code> filter </ code> - 这使得比较变得严格。</ p>
</ div>

展开原文

原文

I think it is the way how filter works. The match in the way you are using it right now is not strict. I think you should use sub in subjectData | filter:{course_name:search.value, semester:semesterSearch.value }:true.

Notice the true value at the end of the filter - this makes the comparison to be strict.

duanba4254
duanba4254 你还有其他方法可以解决这个问题吗?
大约 5 年之前 回复
douhuijun3776
douhuijun3776 mic4ael:我应用了你的答案,但是当我添加了true时,表格值最初根本没有显示,但我只选择显示所选的过滤值。从一开始,所有值都应显示,然后用户可以过滤。
大约 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐