2017-06-15 14 views
0

我目前正在使用ng2完成角2,它適用於搜索與關鍵字。執行ng2完成與自定義搜索

我有2個表:

  • 藝術家
  • 顯示

一個藝術家可以有多個節目,它是一個一對多的關係。

我需要使用藝術家的名字進行搜索,當我使用藝術家名稱進行搜索時,它必須顯示特定「藝術家」的所有「節目」。

這是我的代碼:

this.dataService = completerService.local(this.searchData, 'artisName', 'artisName'); 

回答

0

這樣做會創建一個Subject每當選擇了新的藝術家,將發出修改後的節目列表到dataSource最好的選擇。

public artistsDataService: CompleterData; 
public showsDataService: CompleterData; 

private showsSubject = new Subject(); 

constructor(completerService: CompleterService) { 
    this.artistsDataService = completerService.local(this.artists, 'artisName', 'artisName'); 
    this.showsDataService = completerService.local(this.showsSubject, 'showName', 'showName'); 
} 

public onArtistsSelected(selectedItem: CompleterItem) { 
    if (selectedItem) { 
     const artistShows = this.showsDataService.filter(...); 
     this.showsDataService.next(artistShows); 
    } else { 
     this.showsDataService.next([]); 
    } 
}