我正在使用 React.js 做一個 PWA 測驗應用程序,我遇到了以下問題:我可以獲得只有一個答案的問題對象,有些則有多個。在只有一種可能答案的情況下,我想強制用戶只有一種可能性。為此,我制定了以下算法: clickOnChoice = (key) => { if (this.state && this.state.correctAnswers) { let newChoices = INITIAL_CHOICES; // {} if (this.state.multiChoice) { console.log("this.state.multiChoice:", this.state.multiChoice); // this.state.multiChoice: false ??? newChoices = JSON.parse(JSON.stringify(this.state.choices)); // {answer_b: 1} } newChoices[key] = 1 - (newChoices[key] | 0); // {answer_b: 1, answer_a: 1} this.setState({ choices: newChoices }, this.updateNextButtonState); } }然而,執行似乎忽略了條件if (this.state.multiChoice)。我錯過了什么?https://i.stack.imgur.com/mRrJG.gif 也許我需要一杯咖啡...?無論如何,先謝謝了!
TypeError:如果“false”沒有按預期工作
大話西游666
2023-04-01 17:30:01