【发布时间】:2019-10-20 17:05:40
【问题描述】:
我目前遇到了角度问题。我尝试使用复选框过滤对象数组,但它不起作用。我会尝试按状态过滤我的数组。
当我选中复选框时,我已经尝试使用“ng-true-value”,但由于我的对象数组,它似乎不起作用。
模拟数据.service.ts:
export class MockDataService {
House: Array<object> = [];
constructor() {}
getHouse() {
let options = {min:100, max:500}
const types = ["Maison","Appartement","Bureau","Batiment publique"];
const status = ["En cours","Prêt à publier","Déjà publié","Informations manquantes"];
// const status = [1,2,3,4,5];
for (let i = 0; i < 1; i++) {
const randomTypes = Math.floor(Math.random()*types.length);
const randomStatus = Math.floor(Math.random()*status.length);
this.House.push({
id: faker.random.uuid(),
owner: faker.company.companyName(),
username: faker.internet.userName(),
street: faker.address.streetAddress(),
city: faker.address.city(),
garden: faker.random.number(),
img: faker.image.city(),
surface: faker.random.number(options),
title: faker.lorem.word(),
type: types[randomTypes],
projectStatus: status[randomStatus],
date: faker.date.recent(10)
});
}
return of(this.House);
}
项目列表.component.html:
<input type="checkbox" name="checkbox" [(ngModel)]="checkboxStatus" ng-true-value="'En cours'" ng-false-value="''">
<tr *ngFor="let information of House | filter:searchText | filter:checkboxStatus">
我想要 3 个复选框,当我选中一个复选框时,显示为列表的对象数组应按此复选框进行过滤。
感谢您的帮助!
【问题讨论】:
-
你能指定复选框是多选还是单选(充当单选按钮)?
-
请指定是一次过滤一个状态值还是多个值?
-
您是否使用第三方库进行过滤?还是写了自己的方法?
-
@JoelJoseph 复选框是单选的,我想为我拥有的每个状态设置一个复选框。如果我有“进行中”状态,然后单击“进行中”复选框,它应该只显示具有此状态的项目。
-
@PrashantPimpale 实际上我正在使用 ng2-search-filter 包,但似乎这个包只适用于搜索栏
标签: arrays angular object checkbox filter