【问题标题】:Get the name of the ion-select-option in ionic4获取ionic4中离子选择选项的名称
【发布时间】:2020-01-13 23:21:02
【问题描述】:

我无法从离子选择器中获取名称。我可以使用[(ngmodel)] 从离子选择选项中获取值。但是我可以找到如何从选定的离子选择选项中获取名称。

<ion-item>
      <ion-select placeholder="Select User"  [(ngModel)]="selectedUser" (ionChange)="selectedUser1(selectedUser)" style="width:100%;max-width:100%;">              
          <ion-select-option *ngFor="let item of user" value="{{item.pos_id}}">{{item.pos_name}}</ion-select-option>
        </ion-select>
    </ion-item>

我需要在 typescript 变量中获取 {{item.pos_name}} - 名称。请帮我获取所选离子选择选项的名称

【问题讨论】:

    标签: javascript ionic-framework ionic4


    【解决方案1】:

    1 选项:您可以遍历您的 User 数组以查找名称和其他信息。

    selectedUser1(selectedUser){
     this.user.map(val, index){
       if(selectedUser == val.pos_id){
         console.log(val); // this will print your complete object of user.
      }
     }
    }
    

    2 选项:将名称作为值与您的 id 一起传递。

    &lt;ion-select-option *ngFor="let item of user" value="{{item.pos_id}}, {{item.pos_name}}"&gt;{{item.pos_name}}&lt;/ion-select-option&gt;
    您将在selectedUser ngModel 中获得 id 和 Name。您可以根据需要拆分它。

    【讨论】:

      猜你喜欢
      • 2013-09-12
      • 2017-07-27
      • 2021-05-15
      • 2017-01-23
      • 2018-04-06
      • 2020-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多