我有一个输入,在用户插入文本后,我想在中的按钮中显示每个单词button-group。我拆分了句子并将其映射为返回
button-group
<input .....><button onClick=....>
所以我在输入中插入了文本,单击按钮后,text.split(" ") 一切正常,直到这里。但在按钮组中什么也没显示
text.split(" ")
<div className="btn-group" role="group" aria-label="..."> {this.mapArrayToButtons()} </div> mapArrayToButtons(){ this.state.textArr.map((word)=>{ console.log('the word: ',word); return(<button key={word} type="button" className="btn btn-default" value={word}>{word}</button>);}); }
我看到控制台日志textArr.length时间和逐字记录。但没有呈现按钮,浏览器中也没有任何显示。
textArr.length
您将需要从函数中返回一个值,如下所示:
mapArrayToButtons(){ return this.state.textArr.map((word)=>{ return(<button key={word} type="button" className="btn btn-default" value={word}>{word}</button>);}); }
希望有帮助!