2017-06-15 13 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([]); 
    } 
}