首页 > 解决方案 > 如何批量创建记录

问题描述

我有一个应用程序,用户必须回答 50 个问题。我通过网络服务收到这些问题,相关答案也在网络服务中。我将这些问题分配给票号。每 50 个问题和相关答案属于一张票。

我的问题是显示和保存最终用户的选择。这里的最佳做法是什么。

我使用打字稿和角度。

我目前的做法是:

创建一个包含 50 条记录的表格,每行都有一个下拉列表来回答问题。所以我预取问题并显示下拉列表。

我的问题是我不知道如何访问 50 条记录中的每一行来确定它们是否已回答并保存。

我想一次全部保存(如果全部回答)或一一保存(这不是首选解决方案,因为它可能不是自主事务?)。

我通过对表格使用 formGroup 进行了尝试。但这并不成功。

也许这张桌子是一个完全错误的方法?

任何帮助表示赞赏!奥热雷斯

标签: angulartypescript

解决方案


非常感谢您的回答。我认为最好一次显示所有 50 个问题。下拉列表中有大约 2-5 个答案。

我现在做的是html中的以下内容:

<div class="row justify-content-center">
    <div class="col-8">
        <form name="editForm" novalidate (ngSubmit)="submit()" #editForm="ngForm">
            <h2 id="jhi--entry-heading">Create or edit a  Entry Test</h2>
            <div class="table-responsive" *ngIf="Questions">
                <table class="table table-striped">
                    <thead>
                        <tr jhiSort [(predicate)]="predicate" [(ascending)]="reverse" [callback]="reset.bind(this)">
                            <th jhiSortBy="id"><span>ID</span>
                                <fa-icon [icon]="'sort'"></fa-icon>
                            </th>
                            <th jhiSortBy="name"><span>Question</span>
                                <fa-icon [icon]="'sort'"></fa-icon>
                            </th>
                        </tr>
                    </thead>
                    <tbody infinite-scroll (scrolled)="loadPage(page + 1)" [infiniteScrollDisabled]="page >= links['last']" [infiniteScrollDistance]="0">
                            <tr *ngFor="let Question of Questions ;trackBy: trackId; let i = index;">
                            <th scope="row">{{Question.id}}</th>
                            <td>{{Question.name}} {{Question.description}}</br>
                                      <select class="form-control" id="answerid">
                                        <option disabled hidden [value]="selectUndefinedOptionValue">-- select --</option>
                                        <option *ngFor="let answer of Question.answers; let j = index;" [value]="answer.id">{{answer.description}}</option>
                                    </select>
                            </td>
                        </tr>
                    </tbody>
                    <div>
                        <button type="button" id="cancel-save" class="btn btn-secondary" (click)="previousState()">
                            <fa-icon [icon]="'ban'"></fa-icon>&nbsp;<span>Cancel</span>
                        </button>
                        <button type="submit" id="save-entity" [disabled]="editForm.form.invalid || isSaving" class="btn btn-primary">
                            <fa-icon [icon]="'save'"></fa-icon>&nbsp;<span>Save</span>
                        </button>
                    </div>
        </form>
    </div>

此表工作正常,它是从服务中预填充的,您可以从下拉列表中选择一个项目。但是现在我完全迷失了如何从打字稿访问表中的各个记录。我想访问选定的答案 + 相关问题。我可以将完整的表格作为一个对象接收吗?

谢谢你的帮助!奥热雷斯


推荐阅读