第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

在“for...of”循環(huán)中無法讀取超出第一次迭代的內(nèi)容/迭代為空

在“for...of”循環(huán)中無法讀取超出第一次迭代的內(nèi)容/迭代為空

手掌心 2021-11-04 15:35:56
我有一個數(shù)組,questionsArray,我需要在該數(shù)組中的每個問題中做一些事情。第一次迭代有效,但除此之外,它說它無法讀取 null 的屬性 x。這是為什么?- 這是遍歷數(shù)組的代碼:var insertion = new Promise(async (resolve, reject) => {                    for(const question of questionsArray){                        await db.query('INSERT INTO `ml-questions-data` (`text`, `status`, `question_id`, `answer_text`, `answer_status`, `answer_date`, `item_id`, `seller_id`, `created`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);',                         [question.text, question.status, question.id, question.answer.text, question.answer.status, question.answer.date_created, question.item_id, question.seller_id, question.date_created], (erro)=>{                            if(erro){                                reject(erro)                            }                            else{                                console.log('array iteration! db insertion')                            }                        })                    }                    resolve()                });-這是questionsArray數(shù)據(jù):[    {        "date_created": "2019-09-30T03:18:08.000-04:00",        "item_id": "MLB1329418290",        "seller_id": 158369990,        "status": "ANSWERED",        "text": "olá, gostaria de entender como funciona isso?",        "id": 6553335409,        "deleted_from_listing": false,        "hold": false,        "answer": {            "text": "pois bem, vamos adicionar um texto de resposta no json",            "status": "ACTIVE",            "date_created": "2019-09-30T03:24:52.120-04:00"        },        "from": {            "id": 444188609,            "answered_questions": 2        }    },    {        "date_created": "2019-09-30T03:22:21.000-04:00",        "item_id": "MLB1329418290",        "seller_id": 158369990,        "status": "BANNED",        "id": 6553335807,        "deleted_from_listing": false,        "hold": false,        "answer": null,        "from": {            "id": 444188609,            "answered_questions": 2        }    },    the array goes on.....]
查看完整描述

2 回答

?
慕村225694

TA貢獻1880條經(jīng)驗 獲得超4個贊

“answer”在數(shù)組的第二個元素中為空,因此您無法訪問 question.answer.text。(在數(shù)組的第一個元素中,answer 是一個帶有名為“text”的元素的映射)。

對于嘗試訪問其成員的插入的所有部分,您將需要處理輸入數(shù)組中 answer 為空的情況。


查看完整回答
反對 回復 2021-11-04
?
神不在的星期二

TA貢獻1963條經(jīng)驗 獲得超6個贊

檢查

question.answer?question.answer.text : ""

所以基本上這是對answer object的空檢查。所以如果 answer 不為 null 那么它只會執(zhí)行question.answer.text

否則它將給出/分配“”空值


查看完整回答
反對 回復 2021-11-04
  • 2 回答
  • 0 關(guān)注
  • 144 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號