0

我正在尝试使用 ngl-lightning 库的 ngl-lookup 我想传递一个 any[] 类型的数组而不是 String[],这是我的代码:

 <ngl-lookup [lookup]="lookupManagerUsers" [icon]="true" [image]="'user'" [noResultsText]="'Aucun résultat trouvé'"
            [(pick)]="pickedManagerUser" (pickChange)="managerUserPicked($event)" placeholder="Recherchez un agent..." formControlName="manager_id"
            ngDefaultControl>
            <ng-template nglLookupItem let-item>
              <div class="slds-media__body">
                <span class="slds-media__figure slds-listbox__option-icon">
                  <span class="slds-icon_container slds-icon-standard-user">
                    <svg class="slds-icon slds-icon_small" aria-hidden="true">
                      <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/assets/icons/standard-sprite/svg/symbols.svg#user" />
                    </svg>
                  </span>
                </span>{{item}}
              </div>
            </ng-template>
 </ngl-lookup>

这是我的方法 pickedManagerUser: string = '';

lookupManagerUsers = (query: string, source = this.manager_users): any[] => {
let temp = [];
if (!query) {
  temp = source;
} else {
  const temp2 = source.filter(user => user.first_name.indexOf(query.toLowerCase()) > -1 || user.last_name.indexOf(query.toLowerCase()) > -1);
  for (const m of temp2) {
    temp.push(m);
  }
}
return temp;}


 managerUserPicked(superhero) {
console.log(superhero); }

但这确实是我的问题: 在此处输入图像描述

请有任何帮助

4

2 回答 2

1

尝试打印特定属性而不是整体item,即 {{ item.first_name}} 而不是整个项目作为 {{ item }}。

于 2019-02-14T07:21:38.487 回答
0

感谢 bekos 我解决了问题并将我的代码更改为

 <ngl-lookup [lookup]="lookupManagerUsers" [icon]="true" [image]="'user'" [noResultsText]="'Aucun résultat trouvé'"
            [pick]="pickedManagerUser" (pickChange)="managerUserPicked($event)" placeholder="Recherchez un agent..." formControlName="manager_id"
            ngDefaultControl>
            <ng-template nglLookupItem let-item>
              <div class="slds-media__body">
                <span class="slds-media__figure slds-listbox__option-icon">
                  <span class="slds-icon_container slds-icon-standard-user">
                    <svg class="slds-icon slds-icon_small" aria-hidden="true">
                      <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/assets/icons/standard-sprite/svg/symbols.svg#user" />
                    </svg>
                  </span>
                </span>{{item.first_name}} {{item.last_name}}
              </div>
            </ng-template>
          </ngl-lookup>

这个功能

managerUserPicked(managerUserPicked) {
if (managerUserPicked) {
  this.pickedManagerUser = managerUserPicked.first_name + ' ' + managerUserPicked.last_name;
  console.log(managerUserPicked);
} else {
  this.pickedManagerUser = null;
}}

在此处输入图像描述 在此处输入图像描述

于 2019-02-14T10:10:00.050 回答