我試圖在ReactJs組件中的單擊事件時調用shuffleCards。不過,我收到以下錯誤:React JS未捕獲參考錯誤:未定義函數
Uncaught ReferenceError: shuffleCards is not defined
這裏是我的代碼:
constructor(props) {
super(props);
this.state = {
count: 0
};
}
shuffleCards(array) {
var i = array.length,
j = 0,
temp;
while (i--) {
j = Math.floor(Math.random() * (i+1));
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}
handleClickEvent(event) {
var cards = [
{txt: "A",
isDisplayed: false},
{txt: "B",
isDisplayed: false},
{txt: "C",
isDisplayed: false}
];
if (this.state.count == 0) {
cards = shuffleCards(cards);
}
}
'this.shuffleCards' – zerkms
@zerkms哇不能相信我沒有想到這樣做。有效。謝謝! – janeeyrea