के अंदर अपरिभाषित है मुझे अपने घटक के अंदर कार्यों में this.state
तक पहुंचने में समस्या हो रही है। मैं पहले से ही इतने पर this सवाल पाया और मेरे निर्माता करने का सुझाव दिया कोड कहा:प्रतिक्रिया: 'this.state' घटक घटक
class Game extends React.Component {
constructor(props){
super(props);
...
this.state = {uid: '', currentTable : '', currentRound : 10, deck : sortedDeck};
this.dealNewHand = this.dealNewHand.bind(this);
this.getCardsForRound = this.getCardsForRound.bind(this);
this.shuffle = this.shuffle.bind(this);
}
// error thrown in this function
dealNewHand(){
var allCardsForThisRound = this.getCardsForRound(this.state.currentRound);
}
getCardsForRound(cardsPerPerson){
var shuffledDeck = this.shuffle(sortedDeck);
var cardsForThisRound = [];
for(var i = 0; i < cardsPerPerson * 4; i++){
cardsForThisRound.push(shuffledDeck[i]);
}
return cardsForThisRound;
}
shuffle(array) {
...
}
...
...
यह अभी भी काम नहीं करता। this.state.currentRound
अपरिभाषित है। समस्या क्या है?
वास्तव में यह नहीं बता सकता कि इससे क्या चल रहा है, यह ठीक दिखता है। क्या आप इसे जेएस फीड में अपलोड कर सकते हैं? – JordanHendrix
मुझे नहीं पता कि प्रतिक्रिया कोड के साथ ऐसा कैसे करें। – hellogoodnight
एएस 6 के लिए आधार पहेली और प्रतिक्रिया: https://jsfiddle.net/jhonvolkd/nrd015dm/ – JordanHendrix