Reactjs 内部反应条件渲染。映射空屏幕
我正在尝试使用此函数在内部进行条件渲染:Reactjs 内部反应条件渲染。映射空屏幕,reactjs,Reactjs,我正在尝试使用此函数在内部进行条件渲染: renderNewBuildingModel = () =>{ if(this.state.newBuildingModel){ return( <Modal isOpen={this.state.newBuildingModel} toggle={this.openNewBuildingModel} className={this.props.className}> <ModalHead
renderNewBuildingModel = () =>{
if(this.state.newBuildingModel){
return(
<Modal isOpen={this.state.newBuildingModel} toggle={this.openNewBuildingModel} className={this.props.className}>
<ModalHeader toggle={this.openNewBuildingModel}>New Building</ModalHeader>
<ModalBody>
<ListGroup>
{
this.state.buildings.map((b) => {
<ListGroupItem>
<div className="newBuilding">
<img className="newBuildingImage"src={b.img}/>
<span className="newBuildingName">{b.name}</span>
</div>
<Label className="newBuildingDesc">{b.description}</Label>
<div>
{b.wood != undefined ? <Label className="newBuildingDesc">Wood Cost:{b.wood}</Label>: null}
{b.stone != undefined ? <Label className="newBuildingDesc">Stone Cost:{b.stone}</Label>: null}
</div>
</ListGroupItem>
})
}
</ListGroup>
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={this.openNewBuildingModel}>Cancel</Button>
</ModalFooter>
</Modal>
)
}
}
renderNewBuildingModel=()=>{
if(this.state.newBuildingModel){
返回(
新楼
{
this.state.buildings.map((b)=>{
{b.name}
{b.description}
{b.wood!=未定义?木材成本:{b.wood}:null}
{b.stone!=未定义?石头成本:{b.stone}:null}
})
}
取消
)
}
}
我只是得到空的模型屏幕。这是在添加b.stone之后发生的!=。。。还有b.wood!=。。。条件行
编辑:
我通过返回时间并重写代码解决了我的问题:)我认为您可以删除“console.log(b)”使其正常工作。尝试将标签用括号括起来。我想知道木材成本后的冒号和石头成本后的冒号是否会弄乱你的三元结构,这三元结构也期望在真实和虚假结果之间有一个冒号。