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

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

存儲來自 mongodb 的值并驗證

存儲來自 mongodb 的值并驗證

郎朗坤 2023-09-07 10:11:29
我一直對php和sql比較感興趣,但是我決定更多地了解js。所以,我創(chuàng)建了測驗應用程序。(reactjs、nodejs 和 mongodb)應用程序可以運行!幾乎。有些事情我不滿意,我不知道如何解決。api.jsrouter.get('/', (req, res) => {    Quiz.aggregate([ { $sample: { size: 1 } } ])        .then((data) => {            console.log('Data: ', data);            res.json(data);        })        .catch((error) => {            console.log('erorr: ', error)        })});應用程序.js  getQuestionAndAnswers = () => {    axios.get('http://localhost:8080/api')      .then((response) => {        const data = response.data;        this.setState({posts: data});        console.log('Data has been received');      })      .catch(() => {        alert('Error retrieving data');      })  } displayQuiz = (posts) => {    if (!posts.length) return null    return posts.map((post, index) => (      <div key={index}>        <p>{post.question}</p>        <button value={post.answer} onClick={(e) => this.checkAnswer(e, post)}><p>A. {post.answer}</p></button>        <button value={post.answer2} onClick={(e) => this.checkAnswer(e, post)}><p>B. {post.answer2}</p></button>      </div>    ));  }; checkAnswer = (e,post) => {    console.log(e.currentTarget.value);    if(e.currentTarget.value === post.c_answer){      console.log('correct');    }else{      console.log('incorrect');    }  };正如您所看到的,我將數(shù)據(jù)存儲在按鈕值中,我認為這不是最好的解決方案,因為存儲在那里的答案可能非常大,但我不知道如何做得更好。所以,我必須更改答案檢查,因為此時,我將正確答案與單擊的值進行比較,是否有更好的解決方案?我想添加一個函數(shù),由于錯誤的答案會將顏色更改為紅色,而正確的答案會將顏色更改為綠色,我想在執(zhí)行 if() 后添加 css 類就足夠了。對于我點擊的按鈕來說,做到這一點并不困難,但是其余的呢?感謝您的任何建議!
查看完整描述

目前暫無任何回答

  • 0 回答
  • 0 關(guān)注
  • 107 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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