【问题标题】:Ionic 2 Accordion Group - Showing empty ion-cards where it should not show cards at all if data is not availableIonic 2 Accordion Group - 显示空的离子卡,如果数据不可用,则根本不应该显示卡
【发布时间】:2017-12-17 04:48:15
【问题描述】:

我正在尝试在 ionic 2 中创建手风琴组。单击后,它应该展开并显示“离子卡”,如果数据可用。问题是当我单击展开时,它会显示空的离子卡,如果没有数据,我根本不希望它显示卡。

下面是我的代码:

主页.html

<ion-list *ngFor="let item of items" (click)="toggleGroup(item)" [ngClass]="{active: isGroupShown(item)}">


  <ion-item>
    <ion-icon [name]="item.symbol" color="dark" item-left></ion-icon>
    <h2 [innerHTML]="item.title" class="Ride" item-left></h2>
    <ion-icon color="dark" item-right [name]="isGroupShown(item) ? 'remove' : 'add'"></ion-icon>
  </ion-item>

  <ion-card *ngIf="isGroupShown(item)">
    <ion-item>{{item.description}}
      <button fixed ion-button item-right clear (click)="goToItemDetails()" class="button">View</button>
    </ion-item>
  </ion-card>

</ion-list>

首页.ts

items = [{
    title: "Ride",
    symbol: "car",
    description: "Need a ride"

  },
  {
    title: "Meal",
    symbol: "restaurant",

  },
  {
    title: "Child-Care",
    symbol: "logo-reddit",
    icon: "add"
  },
];

shownGroup = null;

constructor(public navCtrl: NavController, public navParams: NavParams) {

}

toggleGroup(group) {
  if (this.isGroupShown(group)) {
    this.shownGroup = null;
  } else {
    this.shownGroup = group;
  }
};
isGroupShown(group) {
  return this.shownGroup === group;
};

我做错了什么?

截图如下: Here, Ion-card shouldn't be visible or shown when there is no data. On toggle, it should only show card for that category if it is present else nothing

【问题讨论】:

  • 我明白你的问题了吗?当items 没有您不想显示的数据时ion-list
  • @RezaRahmati 添加了应用程序的屏幕截图。当我点击类别时,它应该只在数据存在时才显示卡,否则在切换时它应该是空的并且不会生成空白离子卡。

标签: angular typescript ionic2 accordion


【解决方案1】:

您需要添加更多条件以使卡片可见,例如

  <ion-card *ngIf="isGroupShown(item) && item.description && item.description !== ''">
    <ion-item>{{item.description}}
      <button fixed ion-button item-right clear (click)="goToItemDetails()" class="button">View</button>
    </ion-item>
  </ion-card>

【讨论】:

  • 为离子描述添加了条件,但仍然显示空白卡。
  • 在ion-card前在线添加{{isGroupShown(item)}} {{item.description !== ''}},查看数值是否为true,当显示为空卡时
  • 我也编辑了我的答案,因为我看到你的项目根本没有描述
  • 试过了,但条件不起作用..我想我必须找到另一个解决方案
  • @JBhatt 您是否将此{{isGroupShown(item)}} {{item.description !== ''}} 添加到您的代码中以了解那里发生了什么?
猜你喜欢
  • 2017-11-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-25
  • 1970-01-01
  • 2016-12-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多