首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >填写问卷

填写问卷
EN

Stack Overflow用户
提问于 2018-06-29 01:39:52
回答 2查看 59关注 0票数 0

我正在创建一个移动应用程序,允许用户在问卷中回答一些问题。当问卷完成后,用户将其保存在LocalStorage中。当他在页面上时,用户会看到上面所有的回答问卷的按钮。我想给大家看一下以前填好的问题,但他不能改变任何答案。

我怎么做(禁用任何修改)?

我用的是离子3。

下面是我如何创建问卷的代码示例。

代码语言:javascript
复制
    <ion-item>
      <ion-label>{{ 'PREVISIT_fever_or_infection' | translate }}</ion-label>
      <ion-select [(ngModel)]="qObj.feverinfectionlastrelapse" interface="popover">
        <ion-option value="yes">Yes</ion-option>
        <ion-option value="no" checked>No</ion-option>
      </ion-select>
    </ion-item>

    <ion-item>
      <ion-label>{{ 'PREVISIT_overheated' | translate }}</ion-label>
      <ion-select [(ngModel)]="qObj.overheatedlastrelapse" interface="popover">
        <ion-option value="yes">Yes</ion-option>
        <ion-option value="no" checked>No</ion-option>
      </ion-select>
    </ion-item>

    <p>{{ 'PREVISIT_symptom_experienced' | translate }}<ion-icon name="add" class="more-icon"></ion-icon> {{ 'PREVISIT_symptom_experienced2' | translate }}</p>

    <!-- Symptom list -->
    <ion-item *ngFor="let symptom of symptoms">
      {{symptom.label | translate}}
      <ion-label>{{symptom.label | translate}} <ion-icon name="add" class="more-icon" [hidden]="!symptom.more"></ion-icon></ion-label>
      <ion-checkbox [(ngModel)]="symptom.value"></ion-checkbox>
    </ion-item>

    <!-- more detailed questions list -->
    <div *ngFor="let symptom of symptoms">
        <h5 *ngIf="symptom.value&&symptom.more" class="more-detailed-questions-spacer">{{symptom.label | translate}}</h5>

        <div *ngIf="symptom.value">
          <ion-item *ngFor="let question of symptom.moreList">
              <ion-label>{{question.name | translate}}</ion-label>
              <ion-select [(ngModel)]="question.value" interface="popover">
                <ion-option *ngFor="let condition of question.conditions" [value]="condition.value">{{condition.txt}}</ion-option>  
              </ion-select>
            </ion-item>

以下是调查问卷的截图。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-06-29 02:02:00

您可以使用变量类型布尔型的主题,并使用相同的变量检查用户是否已加载详细信息并使用[disabled]="yourBoolean"禁用窗体/元素。

如果你有单一的形式,你不需要去一个主题,你可以只使用一个布尔变量

代码语言:javascript
复制
this.qObj = JSON.parse(localStorage.getItem('qObj'));
this.readOnly = true;

代码语言:javascript
复制
<ion-select  [disabled] = "readOnly" [(ngModel)]="qObj.feverinfectionlastrelapse" interface="popover">
票数 1
EN

Stack Overflow用户

发布于 2018-06-29 02:05:42

你可以在你的问卷上保持一个只读状态,

代码语言:javascript
复制
this.qObj = JSON.parse(localStorage.getItem('qObj'));
this.isReadOnly = typeof qObj !== 'undefined' && qObj !== null

对于输入控件,可以分配这个变量。

代码语言:javascript
复制
<ion-item>
  <ion-label>{{ 'PREVISIT_fever_or_infection' | translate }}</ion-label>
  <ion-select [disabled] = "isReadOnly" [(ngModel)]="qObj.feverinfectionlastrelapse" interface="popover">
    <ion-option value="yes">Yes</ion-option>
    <ion-option value="no" checked>No</ion-option>
  </ion-select>
</ion-item>

<ion-item *ngFor="let symptom of symptoms">
  {{symptom.label | translate}}
  <ion-label>{{symptom.label | translate}} <ion-icon name="add" class="more-icon" [hidden]="!symptom.more"></ion-icon></ion-label>
  <ion-checkbox [disabled] = "isReadOnly" [(ngModel)]="symptom.value"></ion-checkbox>
</ion-item>

<ion-item>
  <ion-label color="primary">Inline Label</ion-label>
  <ion-input [readonly]="isReadOnly" placeholder="Text Input"></ion-input>
</ion-item>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51093197

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档