Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular Mat同时在多个字段上自动完成搜索_Angular_Angular Material - Fatal编程技术网

Angular Mat同时在多个字段上自动完成搜索

Angular Mat同时在多个字段上自动完成搜索,angular,angular-material,Angular,Angular Material,我有一个包含5000个对象的mat autocomplete。每个对象都包含一个名字和一个姓氏 我想能够同时搜索名字和姓氏,无论输入的顺序如何。目前我只能搜索两个字段中的一个 private _filterClients(value: string): any[] { const filterValue = value.toLowerCase(); return this.options.filter(option => option.first_name

我有一个包含5000个对象的mat autocomplete。每个对象都包含一个名字和一个姓氏

我想能够同时搜索名字和姓氏,无论输入的顺序如何。目前我只能搜索两个字段中的一个

private _filterClients(value: string): any[] {
    const filterValue = value.toLowerCase();
    return this.options.filter(option => 
        option.first_name.toLowerCase().indexOf( filterValue ) > -1 || 
        option.last_name.toLowerCase().indexOf( filterValue ) > -1
   );
}
我的目标是当我输入Bill Ga。。。我得到了最可能的建议。同样的事情,如果我键入门Bi


我不知道如何实现这一点。非常感谢您的帮助。

这是一个复杂的问题,有时我们并不认为有复合名称。在我的国家,我们无法区分哪个是中间名,哪个是第一个姓氏,或者第二个姓氏,所以我会尝试这样的实现:

let filterValues : string[] = value.toLowerCase().split(" ");
let results : any[][];
let arrayAux: any[][];

/**
 * We identify which of the options contains each of the words incorporated 
 * in the filter, the idea is if we introduce 2 words, obtain an array of 2
 * positions, the first will be the options that contain the first word and the
 * next the second word, regardless of if it is in the first or last name.
 */
filterValues.forEach((filterValue : string) => {
    results.push(this.options.filter(option => 
            option.first_name.toLowerCase().indexOf( filterValue ) > -1 || 
            option.last_name.toLowerCase().indexOf( filterValue ) > -1);
});

/**
 * Once we have an array for each word entered in the filter, we must 
 * obtain the options that are repeated in all the lists.
 */
if (results.length > 0){
    arrayAux.concat(results[0]);
    
    results.forEach((result: string[]) => {
        arrayAux.concat(result);
        arrayAux = arrayAux.filter((e, i, a) => a.indexOf(e) !== i);
    });
}

return arrayAux;
举个例子,让你了解复合名,因为它并不是在所有国家都出现,例如在我的国家西班牙,歌手朱利奥·伊格莱西亚斯他的真名是“朱利奥·何塞·伊格莱西亚斯·德拉库埃娃”,朱利奥·何塞是他的名字,伊格莱西亚斯是第一个姓氏,德拉库埃娃是第二个姓氏

由于这种类型的名称,有必要与过滤器中的所有单词进行比较,因为在过滤器的相同输入中,无法自动知道哪个单词对应于名字、姓氏等