这就是我现在正在做的事情。我有一个数据表,有一些选项来过滤他的内容:
HTML组件:
<div class="row topbuffer-20">
<div class="col">
<h3>Thief: The Dark Project</h3>
<p>There are <span *ngIf="fanmissions"><strong>{{fanmissions.length}}</strong></span> available Fan Missions. The last released is <strong>Veniam in Sunt Pariatur</strong> and the last updated is <strong>Ullamco Ad in Elit</strong>.</p>
</div>
</div>
<div class="row">
<div class="col">
<form>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-search fa-fw"></i></span>
<input class="form-control" [(ngModel)]="searchinput" name="searchinput" placeholder="Search a Fan Mission..." type="text">
</div>
</form>
</div>
<div class="col">
<div class="btn-group">
<span class="btn-group-addon"><i class="fa fa-filter fa-fw"></i></span>
<button type="button" class="btn btn-secondary" data-game-short="tdp">Thief: The Dark Project</button>
<button type="button" class="btn btn-secondary" data-game-short="tg">Thief Gold</button>
<button type="button" class="btn btn-secondary" data-game-short="tma">Thief II: The Metal Age</button>
</div>
</div>
</div>
<div class="row topbuffer-20">
<div class="col">
<table class="table table-hover table-bordered table-sm">
<thead class="thead-default">
<tr>
<th class="align-middle text-center">#</th>
<th class="align-middle">Fan Mission</th>
<th class="align-middle text-center">Game</th>
<th class="align-middle text-center">Version</th>
<th class="align-middle text-center">NewDark</th>
<th class="align-middle text-center">First release</th>
<th class="align-middle text-center">Last update</th>
</tr>
</thead>
<tbody>
<tr class="ectm-listedfanmission" *ngFor="let fanmission of fanmissions | EctmOrderFMsBy: 'name' | EctmFilterFMsBySearch: searchinput; let i = index">
<td class="align-middle text-center" scope="row">{{fanmission.index}}</td>
<th class="align-middle text-capitalize">
<small>{{fanmission.details.author.join(', ')}}</small><br>
{{fanmission.name}}
</th>
<td class="align-middle text-center" title="{{fanmission.details.game.name}}"><small>{{fanmission.details.game.short}}</small></td>
<td class="align-middle text-center"><small>{{fanmission.details.version}}</small></td>
<td class="align-middle text-center" *ngIf="fanmission.details.isNewdark; else newdarknotrequired"><i class="fa fa-check text-success"></i></td>
<ng-template #newdarknotrequired><td class="align-middle text-center"><i class="fa fa-times text-danger"></i></td></ng-template>
<td class="align-middle text-center"><small>{{fanmission.details.firstreleasedate | date:'yyyy/MM/dd'}}</small></td>
<td class="align-middle text-center"><small>{{fanmission.details.lastupdatedate | date:'yyyy/MM/dd'}}</small></td>
</tr>
</tbody>
</table>
</div>
</div>
我必须做的事情:
我需要创建自定义管道并将其应用于我的 ectm-list.component 。
请考虑在GitHub上查看我的项目,以便了解它的结构:http://www.github.com/jonathanlinat/enhanced-cheapthiefmissions/
有人可以帮助我完成这项重大任务吗?
目前,我只能按 NAME 进行过滤。这是我的管道:
@Pipe({
name: 'EctmFilterFMsBySearch'
})
export class EctmFilterFMsBySearchPipe implements PipeTransform {
transform(value: any, arg: any): any {
if (value != null && arg != null) {
var filteredfanmissions = value.filter((fanmission) => fanmission.name.search(new RegExp(arg, "i")) >= 0);
if (filteredfanmissions != 0) {
return filteredfanmissions;
}
} else {
return value;
}
}
}
正如你在这里看到的那样......
value.filter((fanmission) => fanmission.name.search(new RegExp(arg, "i")) >= 0);
...我需要通过应用帖子顶部列出的内容来更改 fanmission.name 。我怎样才能做到这一点?我需要使用循环吗?
答案 0 :(得分:1)
我在开发我的应用程序时面临同样的情况,我不喜欢使用过滤器作为管道。相反,您可以将其用作服务,并将列名称和输入文本作为变量传递给函数。然后你可以返回fanmission。&#34;列名,即name / id&#34; .search(新的RegExp(arg,&#34; i&#34;))&gt; = 0)