Angular - 无法在表单输入框中访问或查看网格中的选定数据

问题描述 投票:0回答:1

我在表单的输入框中显示单行数据时遇到问题。

网格视图:(数据存储在selectedTrade数组中)

<p-table [value]="trades" [paginator]="true" selectionMode="single" [(selection)]="selectedTrade">
  <ng-template pTemplate="body" let-trades>
    <tr [pSelectableRow]="trades">
      <td><button pButton #Buy name="Buy" type="button" (click)="showDialog()"></button>
      </td>
      <td><button pButton #Sell name="Sell" type="button" (click)="showDialog()"></button>
      </td>
      <td *ngFor="let col of cols">
        {{trades[col.field]}}
      </td>
    </tr>
  </ng-template>
</p-table>

对话框涉及带有输入框的表单。当对话框打开时,我需要输入框中selectedTrade数组的值。

selectedTrade Json结构{instrumentid:'1',工具:'特斯拉',buyPrice:'2000','buyQty':'9','sellPrice':'5000','sellQty':'25'}

我需要将它与输入绑定:Instrument,Transaction_Quantity,Transaction_Price,具体取决于买入或卖出对话框。我在绑定或显示值方面遇到问题。请帮忙。

<p-dialog header="Orders" [(visible)]="ordersDialog" [modal]="true">
<form name="editForm" role="form" novalidate (ngSubmit)="save(editForm.value)" #editForm="ngForm">
  <div>
    <input type="text" class="form-control" name="instrument_id" id="instrument_id" ngModel #instrument_id="ngModel" />
    <input type="text" class="form-control" name="at_price" id="field_at_price" ngModel #at_price="ngModel" />
    <input type="text" class="form-control" name="transaction_quantity" id="transaction_type" ngModel #transaction_quantity="ngModel" />
  </div>
  <button type="submit" class="btn btn-primary"> <span>Save</span></button>
</form>
</p-dialog>
angular primeng angular7 angular-ngmodel angular-forms
1个回答
0
投票

如果你得到的数据超过需要从你的模型中获取数据(即你的col)

<input type="text" class="form-control" name="instrument_id" id="instrument_id" [(ngModel)]="col.instrument_id" />
© www.soinside.com 2019 - 2024. All rights reserved.