如何动态地将文本框唯一的行?

发布于 2025-02-12 05:35:20 字数 2082 浏览 0 评论 0原文

我创建了一个矩阵,其中包含多个文本框。我希望文本框为列独特地工作。我从API nd获取行和列的数据,然后必须将其添加到表中。

HTML文件

<div class="card" *ngIf="inputQuestionType == 'matrixtextbox'">
    <div class="header custom-justify-content-space-between">
        <h2>{{QuestionDescription}}<span *ngIf="questionSettin[0].value" style="color: red;"> *</span></h2>
        <mat-icon matSuffix title="{{AnswerHint}}" *ngIf="AnswerHint && AnswerHint != ''">help_outline</mat-icon>
    </div>
    <div class="body">
        <div *ngIf="dataValue.length > 0 && displayColumns.length >0">
        <table mat-table [dataSource]="dataValue" style="width: 100%;">
            <ng-container matColumnDef="question">
          <th mat-header-cell *matHeaderCellDef></th>
          <td mat-cell *matCellDef="let row=index">{{dataValue[row]}}</td>
          </ng-container>
          
            <ng-container
              *ngFor="let innerColumn of displayColumns;let i=index"
              [matColumnDef]="innerColumn">
            
              <th mat-header-cell *matHeaderCellDef>{{displayColumns[i]}}</th>
              <td mat-cell *matCellDef="let element;let row=index">
                <mat-form-field class="example-full-width" appearance="outline">
                    <!-- <mat-label>Input</mat-label> -->
                    <input matInput type="text" autocomplete="off" (change)="radiochange($event)" [(ngModel)]="dataSer.previewQAns">
                </mat-form-field>
              </td>
            </ng-container>
            <tr mat-header-row *matHeaderRowDef="allColumns"></tr>
            <tr mat-row *matRowDef="let row; columns: allColumns"></tr>
          </table>
        </div>
    </div>

我正在添加我要下面的输出映像。当我在1个文本框中输入一个值时,所有文本框都通过相同的插入更改。 输出

I have created a matrix, which contains multiple textbox. I want textbox to be worked uniquely for the column. I am getting the data of row and column from the API nd then it has to getting added to the table.

Html file

<div class="card" *ngIf="inputQuestionType == 'matrixtextbox'">
    <div class="header custom-justify-content-space-between">
        <h2>{{QuestionDescription}}<span *ngIf="questionSettin[0].value" style="color: red;"> *</span></h2>
        <mat-icon matSuffix title="{{AnswerHint}}" *ngIf="AnswerHint && AnswerHint != ''">help_outline</mat-icon>
    </div>
    <div class="body">
        <div *ngIf="dataValue.length > 0 && displayColumns.length >0">
        <table mat-table [dataSource]="dataValue" style="width: 100%;">
            <ng-container matColumnDef="question">
          <th mat-header-cell *matHeaderCellDef></th>
          <td mat-cell *matCellDef="let row=index">{{dataValue[row]}}</td>
          </ng-container>
          
            <ng-container
              *ngFor="let innerColumn of displayColumns;let i=index"
              [matColumnDef]="innerColumn">
            
              <th mat-header-cell *matHeaderCellDef>{{displayColumns[i]}}</th>
              <td mat-cell *matCellDef="let element;let row=index">
                <mat-form-field class="example-full-width" appearance="outline">
                    <!-- <mat-label>Input</mat-label> -->
                    <input matInput type="text" autocomplete="off" (change)="radiochange($event)" [(ngModel)]="dataSer.previewQAns">
                </mat-form-field>
              </td>
            </ng-container>
            <tr mat-header-row *matHeaderRowDef="allColumns"></tr>
            <tr mat-row *matRowDef="let row; columns: allColumns"></tr>
          </table>
        </div>
    </div>

I am adding the output image which I am getting below. When I enter a value in 1 textbox all the textbox are getting changed with the same imput.
Output

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄荷港 2025-02-19 05:35:20

我通过将不同的值分配给不同的文本框来解决此问题。我已经动态添加了值,还为输入标签添加了名称字段。这给了我不同的值,以便我可以独特地使用所有文本框。

<div class="body">
        <div *ngIf="dataValue.length > 0 && displayColumns.length >0">
        <table mat-table [dataSource]="dataValue" style="width: 100%;">
            <ng-container matColumnDef="question">
          <th mat-header-cell *matHeaderCellDef></th>
          <td style="width: 10%;" mat-cell *matCellDef="let row=index">{{dataValue[row]}}</td>
          </ng-container>
          
            <ng-container
              *ngFor="let innerColumn of displayColumns;let i=index"
              [matColumnDef]="innerColumn">
            
              <th class="text-center" style="width: 20%;" mat-header-cell *matHeaderCellDef>{{displayColumns[i]}}</th>
              <td mat-cell *matCellDef="let element;let row=index">
                <mat-form-field class="example-full-width" appearance="outline">
                    <input matInput type="text" autocomplete="off"
                    [(ngModel)]="valueCheckboxMatrix[row][i]"
                    [name]="'rd'+row"
                    (change)="valueChangeMatrixTextbox($event,dataValue[row],displayColumns[i])">
                </mat-form-field>
              </td>
            </ng-container>
            <tr mat-header-row *matHeaderRowDef="allColumns"></tr>
            <tr mat-row *matRowDef="let row; columns: allColumns"></tr>
          </table>
        </div>
    </div>

I solved this issue by assigning different value to different textbox. I have added value dynamically and also added an name field to input tag. Which gives me different values so that I can use all textboxes uniquely.

<div class="body">
        <div *ngIf="dataValue.length > 0 && displayColumns.length >0">
        <table mat-table [dataSource]="dataValue" style="width: 100%;">
            <ng-container matColumnDef="question">
          <th mat-header-cell *matHeaderCellDef></th>
          <td style="width: 10%;" mat-cell *matCellDef="let row=index">{{dataValue[row]}}</td>
          </ng-container>
          
            <ng-container
              *ngFor="let innerColumn of displayColumns;let i=index"
              [matColumnDef]="innerColumn">
            
              <th class="text-center" style="width: 20%;" mat-header-cell *matHeaderCellDef>{{displayColumns[i]}}</th>
              <td mat-cell *matCellDef="let element;let row=index">
                <mat-form-field class="example-full-width" appearance="outline">
                    <input matInput type="text" autocomplete="off"
                    [(ngModel)]="valueCheckboxMatrix[row][i]"
                    [name]="'rd'+row"
                    (change)="valueChangeMatrixTextbox($event,dataValue[row],displayColumns[i])">
                </mat-form-field>
              </td>
            </ng-container>
            <tr mat-header-row *matHeaderRowDef="allColumns"></tr>
            <tr mat-row *matRowDef="let row; columns: allColumns"></tr>
          </table>
        </div>
    </div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文