简体   繁体   English

单击特定的离子项目按钮会触发离子3中的其他按钮

[英]Clicking on specific ion-item button triggers the other buttons in ionic 3

Lets suppose there are n elements in the array of item. 假设item数组中有n个元素。 So, the below html will display n items with arrow-dropup click button attached to every item. 因此,下面的html将显示n个项目,每个项目都附有箭头下拉式单击按钮。

 <div *ngFor="let item of medicineName; let i = index">
  <ion-list>
    <ion-item >
      <ion-thumbnail item-start  >
        <img src="/assets/imgs/tablet.png" class="thumbnail">
      </ion-thumbnail>
      <h2 style="color: #070779;font-weight: bold;">{{item.medicine_name}}</h2>
      <div class = "done" *ngIf="showDiv">
        <ion-icon name="done-all"></ion-icon>
      </div>
      <p>{{item.instruction}} | {{item.days}}</p>
      <button  ion-button clear item-end (click)="toggle()">
       <ion-icon name="arrow-dropup" *ngIf="visible[index]"></ion-icon>
   <ion-icon name="arrow-dropdown" *ngIf="!visible[index]"></ion-icon>
     </button>
     <button ion-button icon-only *ngIf="showBtn" style="width: 30%">SKIP</button>
     <button ion-button icon-only *ngIf="showBtn" (click)="showIcon()" style="width: 30%">TAKE</button>
   </ion-item>
  </ion-list>
</div>

.ts code .ts代码

toggle(index){
  this.visible[index] = !this.visible[index];
if(this.showBtn == true){
  this.showBtn = false;
} else {
  this.showBtn = true ;
}

在此处输入图片说明

Requirement : I only want the particular button change with visible=true, and not all the buttons. 要求 :我只希望特定按钮更改为visible = true,而不是所有按钮更改。

Problem : When clicking on arrow Click button of respective ion-item, the other ion-item does not get effected. 问题 :单击箭头时, Click相应离子项目的按钮,其他离子项目不会生效。

在此处输入图片说明

You're only using one variable for your display ie visible , therefore once you click on one, it's toggled to true and all the items show expanded. 您只在显示中使用一个变量,即visible ,因此,一旦单击一个变量,它就会切换为true并且所有项目都将显示为展开状态。

You need to have multiple variables to handle the different dropdowns, add an index to your ngFor , and then change click handler to (click)="toggle(index)" 您需要具有多个变量来处理不同的下拉菜单,将索引添加到ngFor ,然后将单击处理程序更改为(click)="toggle(index)"

visible: boolean[];    

toggle(index) {
  this.visible[index] = !this.visible[index];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM