[英]React JS: Extract Inner HTML
I have a function which returns 2 buttons wrapped in a span
tag. 我有一个函数,该函数返回包裹在
span
标记中的2个按钮 。 I want to extract the buttons
from the span
so it can take advantage of Bootstrap styles. 我想从
span
提取buttons
,以便可以利用Bootstrap样式。
Here is the buttons function: 这是按钮功能:
changesButtons: function()
{
if( ! this.state.textChanged)
{
return null;
}
else
{
return (
<span>
<button className="btn btn-primary">Save</button>
<button className="btn btn-default">Undo</button>
</span>
);
}
},
and here is the render function: 这是渲染函数:
render: function()
{
console.log(this.changesButtons());
return (
<div className="input-group">
<span className="input-group-addon">
<input
type="checkbox"
name="task-done"
id="task-done"
checked={this.state.taskDone}
onChange={this.handleDoneChanged}
/>
</span>
<input type="text"
className="form-control"
name="item-name"
id="item-name"
value={this.state.itemName}
onChange={this.handleTextChange}/>
<span className="input-group-btn">
{this.changesButtons()}
<button className="btn btn-warning"
type="button"
name="delete-item"
id="delete-item"
onClick={this.handleDeleteClicked}>
<i className="fa fa-trash"></i>
</button>
</span>
</div>
);
}
Right now, the span is rendered too so the buttons don't have the button group styles applied to them. 现在,跨度也被渲染,因此按钮没有应用按钮组样式。
Do not create a function changesButtons()
. 不要创建函数
changesButtons()
。 replace {changesButtons()}
by: 将
{changesButtons()}
替换为:
{this.state.textChanged?
<span>
<button className="btn btn-primary">Save</button>
<button className="btn btn-default">Undo</button>
</span>
:null}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.