亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在給定的對象中以串行方式檢索索引值

如何在給定的對象中以串行方式檢索索引值

眼眸繁星 2022-06-16 17:17:17
在給定的對象中,有不同的問題集。(標簽,問題文本),每個對象集都有“QuestionTypeId”。如果 QuestionTypeId 為“18”,則問題為“標簽”,標簽不應包含數字(索引值)。每個標簽可能有一個或多個帶有索引值的 questionText。在這里,我只需要向 QuestionTypeId 不同而不是“18”的 questionText 顯示索引值。只有那些問題文本編號或索引值需要連續添加,下面是以正確格式顯示的圖像。圖像中顯示的結果是我試圖得到下面是我試圖得到結果的代碼:export class AppComponent implements OnInit {  globalJsonData = {    "parent": {      "child": [{          "QuestionId": 349,          "QuestionText": "This is Label One",          "QuestionTypeId": 18,          "QuestionSetCode": 166378        },        {          "QuestionId": 340,          "QuestionText": "This is Question Text One",          "QuestionTypeId": 17,          "QuestionSetCode": 166378        },        {          "QuestionId": 350,          "QuestionText": "This is Label Two",          "QuestionTypeId": 18,          "QuestionSetCode": 166378        },        {          "QuestionId": 352,          "QuestionText": "This is Question Text Two",          "QuestionTypeId": 17,          "QuestionSetCode": 166378        },        {          "QuestionId": 354,          "QuestionText": "This is Question Text Three",          "QuestionTypeId": 6,          "QuestionSetCode": 166378        },        {          "QuestionId": 350,          "QuestionText": "This is Label Three",          "QuestionTypeId": 18,          "QuestionSetCode": 166378        },        {          "QuestionId": 353,          "QuestionText": "This is Question Text Four",          "QuestionTypeId": 17,          "QuestionSetCode": 166378        },        {          "QuestionId": 355,          "QuestionText": "This is Question Text Five",          "QuestionTypeId": 8,          "QuestionSetCode": 166378        }      ]    }  }使用上述解決方案,我得到了這個結果:請幫助我獲得解決方案,或為每個跳過標簽的問題文本以串行方式索引值。
查看完整描述

1 回答

?
素胚勾勒不出你

TA貢獻1827條經驗 獲得超9個贊

你應該循環li不上ul。它也可以以更簡單的方式完成。


你應該這樣做:


在component.ts文件中,按如下方式處理您的數據:


callGenerateConfig() {

    let data = [];

    data = this.globalJsonData.parent.child;

    let position = 1;


    data.forEach((item, index) => {

      let isLabel = item.QuestionTypeId === 18;

      console.log(isLabel);

      let obj = {

        label: isLabel,

        data: item,

        location: position

      }

      if (!isLabel) {

        position++;

      }

      this.questionList.push(obj);

    })

  }

在component.html下面做:


<ul>

   <li *ngFor="let data of questionList">

      <span *ngIf="data.label===false"> {{data.location}}</span>

      <span> {{data.data.QuestionText}}</span>

   </li>  

</ul>


查看完整回答
反對 回復 2022-06-16
  • 1 回答
  • 0 關注
  • 85 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號