【发布时间】:2016-11-13 11:24:18
【问题描述】:
我对 AngularJS 比较陌生,我正在尝试使用 ng-repeat 来显示我学校可用的模块。此外,尝试使用过滤器功能通过文本框过滤掉模块(模块代码和模块标题)。但是,经过数小时的尝试,我没有做到:C。有没有人指导我如何过滤我的数据?
angular.forEach(moduleList, function(value,key){
$scope.modList.push({
ModuleCode : moduleList[key].ModuleCode,
ModuleTitle : moduleList[key].ModuleTitle,
Semesters : moduleList[key].Semesters
});
});
<rd-widget>
<rd-widget-header icon="fa-search" title="Module Search">
<input type="text" ng-model = "searchBox" placeholder="Search" class="form-control input-md" ng-keypress="test($event)"/>
<p>{{searchBox}}</p>
</rd-widget-header>
<rd-widget-body classes="medium no-padding">
<div class="table-responsive">
<table class="table fixed-header">
<thead>
<tr>
<th class="text-center" data-ng-click="orderBy('ModuleCode')">Module Code</th>
<th class="text-center" data-ng-click="orderBy('ModuleTitle')">Module Name</th>
<th class="text-center" data-ng-click="orderBy('Semesters')">Semester</th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat = "modules in modList | filter:filterMod">
<td class="text-center">{{modules.ModuleCode}}</td>
<td class="text-center">{{modules.ModuleTitle}}</td>
<td class="text-center">{{modules.Semesters}}</td>
</tr>
</tbody>
</table>
</div>
</rd-widget-body>
<rd-widget>
$scope.filterMod = function(module){
if(!$scope.searchBox || module.ModuleCode.toLowerCase().indexOf($scope.searchBox) != -1){
return true;
}else{
return false;
}
};
【问题讨论】:
-
好吧,
filterMod是什么? -
我已经更新了代码。它在btm。我认为尝试通过自定义过滤器功能进行过滤是行不通的
标签: angularjs filter html-table ng-repeat