[英]How to filter array table in ng-zorro table?
我是 Angular 的新用戶。
我有一個這樣的演示數組:
for (let index = 1; index <= 100; index++) {
this.listOfData.push([
`Name ${index}`,
`Math.floor(Math.random() * 100)`,
'Employee',
]);
}
我嘗試使用搜索 function 創建一個過濾表:
onSearch = (value) => {
const output = this.listOfData.filter((arr) =>
arr.some((item) => {
item.toLowerCase().includes(value);
})
);
console.log('output: ', output);
this.listOfDisplayData = output;
};
這是我的演示
因此,基本上您的數據項是[[string,string,string],...]
當您開始使用filter
進行過濾時,您必須返回true
才能包含它,返回false
才能將其過濾掉。
這應該解決它
onSearch = (value) => {
const output = this.listOfData.filter((arr) =>
arr.some((item) => {
if (item.toLowerCase().includes(value)) {
return true;
} else {
return false;
}
})
);
console.log('output: ', output);
this.listOfDisplayData = output;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.