小编Joa*_*oan的帖子

JS:处理 find() 属性未定义

我有一个方法,它从数组中的一个元素返回一个值。并非所有元素都具有我想要返回的属性。我想使用方法在一行中完成此功能find()。我试过这种方法来解决它:

getExecsFromTour(tourId){
 return this.repInfo.find(el => el.id == tourId ).execs || [];
}
Run Code Online (Sandbox Code Playgroud)

但是不包含该属性的元素execs返回undefined.

为了解决这个问题,我不得不将结果存储在一个局部变量中:

getExecsFromTour(tourId){
    let items       = this.repInfo.find(el => el.id == tourId);
    return items    != undefined ? items.execs : [];
}
Run Code Online (Sandbox Code Playgroud)

但是我想知道我是否遗漏了什么,这个功能可以用一句话来实现。

javascript find typescript ecmascript-2017

5
推荐指数
2
解决办法
7952
查看次数

固定离子卡在屏幕顶部 Ionic 3

我正在尝试修复屏幕顶部的卡片。我正在尝试这样做,<ion-content>但经过多次尝试后我没有解决它。我试过ion-fixed,但它也不起作用。

我想修复这部分代码:

<ion-card text-center>
   <ion-card-content>
      <h5 style=" font-size: 180%;"> {{selectedItem | noneSelectedItem}}
      </h5>
   </ion-card-content>
</ion-card>
Run Code Online (Sandbox Code Playgroud)

然后,它遵循一个列表:

<ion-card style="background-color:rgb(177, 55, 47);" >
   <br>
   <p class="titleCard">Lista de la carta</p>
   <ion-card-content>
      <ion-list class="accordion-list" >
         <!-- First Level -->
         <ion-list-header *ngFor="let item of information; let i = index" no-lines no-padding>
           <!-- Toggle Button -->
           <button ion-item (click)="toggleSection(i)" detail-none [ngClass]="{'section-active': item.open, 'section': !item.open}">
             <ion-icon item-left name="arrow-forward" *ngIf="!item.open"></ion-icon>
             <ion-icon item-left name="arrow-down" *ngIf="item.open"></ion-icon>
             {{ item.name }}
           </button>
      etc...
Run Code Online (Sandbox Code Playgroud)

所以我的疑问是如何在滚动列表时修复第一张卡片。

非常感谢。

css scroll css-position ionic-framework

3
推荐指数
1
解决办法
6754
查看次数