我有可觀察到的一個陣列的可觀察到的陣列篩選數據:角4個rxjs:
schools: Observable<SchoolVM[]>;
我需要此可觀察到過濾到另一個用於自動填充選擇
filteredSchools: Observable<SchoolVM[]>;
予訂閱form.valueChanges
this.formChange = this.searchForm.valueChanges
.debounceTime(300)
.subscribe(value => {
this.filteredSchools = this.schools.filter(s => s.SchoolName == value);
});
我有一個錯誤:屬性'SchoolName'不存在類型'Sch oolVM []' 我該如何解決它? 還有:我必須過濾2個不同的標準。這是正確的過濾像
this.filteredSchools = this.schools.filter(s => s.SchoolName == value ||
s => s.SchoolName == value);
我改寫了以下Aakash Jain's answer,這樣的功能:
this.formChange = this.searchForm.valueChanges
.debounceTime(300)
.subscribe(value => {
this.filteredSchools = this.schools.map(schools => {
return schools.filter((school: SchoolVM) => (school.SchoolName === value) || (school.City === value));
// this.logger.info(this.filteredSchools);
});
});
,現在我得到的錯誤「schools.filter」不是一個函數。
可觀察
schools: Observable<SchoolVM[]>;
是從HttpClient的通話填補:
this.schoolService.filterSchools(arg)
.subscribe(d => {this.schoolsToFilter = d; })
而且在服務:
filterSchools(arg: string): Observable<any> {
return Observable.from(this.http.get('/api/school/find/' + arg));
也許他們是可觀察到的一個問題,但學校可觀察到的很好填充:
{ 「SchoolID」:13028, 「SchoolName」: 「100%Conduite」, 「城市」: 「MEUDON」, 「郵編」: 「92190」, 「街」: 「17街德加侖」 , 「手機」: 「01 49 66 06 02」 }, { 「SchoolID」:6803, 「SchoolName」: 「100%PERMIS」, 「城市」: 「巴東維萊」, 「郵編」: 「54540」, 「街」: 「25街報馬雷夏爾福煦」, 「電話」: 「」 },...
我改寫這樣的自動選擇的代碼: this.formChange = this.searchForm.valueChanges .debounceTime(300) .subscribe(值=> { this.filteredSchools = this.schools.map(學校((School:SchoolVM)=>(school.SchoolName === value)||(school.City === value)); // this.logger.info(this.filteredSchools ); }); });現在我得到錯誤「schools.filter不是一個函數」。請幫忙嗎? – Marcos
@Marcos嘗試'this.formChange = this.searchForm.valueChanges.debounceTime(300).subscribe(val ue => this.schools.subscribe(schools => console.log(schools)))'讓我知道什麼它記錄。 –
非常感謝您的幫助Aakash。與您的函數我有錯誤錯誤TypeError:_this.schools.subscribe不是一個函數。也許是因爲學校是可觀察的? –
Marcos