0
我有一個搜索欄,我希望能夠搜索我收到的JSON或對象數組的所有字符串或列,用我希望的管道創建。所以我可以在我的表格中更新這個結果。查找和過濾管道的所有內容Array作爲JSON格式Angular 2
我有什麼直到現在自管:(沒有做什麼,我想)
transform(items: any[], args:string): any {
let keys = [];
for (let key in items) {
keys.push({key: key, value: items[key]});
}
let ans = [];
for (let k in keys){
if(items[k].value.match('^.*' + args +'.*$')){
ans.push({key: k, value: items[k]});
}
}
return ans; }
搜索HTML <input type="text" #filterInput (keyup)="0">
加載表調用管
<tbody *ngIf="usersBool">
<tr *ngFor="let entry of content | filterArrayOfObjects: filterInput" >
<td>{{entry.value.enrollmentId}}</td>
<td>{{entry.value.firstName}}</td>
<td>{{entry.value.LastName}}</td>
<td>{{entry.value.typeOfUser}}</td>
<td>edit</td>
<td>delete</td>
</tr>
</tbody>
我有一個虛擬內容叫做:
this.content = [
{
"enrollmentId": "A0xxxxxx",
"firstName": "Bob",
"LastName": "Bob",
"typeOfUser": 'Admin'
},
{
"enrollmentId": "A0xxxxxx",
"firstName": "Bob",
"LastName": "Bob",
"typeOfUser": 'Admin'
},
{
"enrollmentId": "A0xxxxxx",
"firstName": "Bob",
"LastName": "Bob",
"typeOfUser": 'Admin'
}
];