Javascript 反应-从返回条件中删除空DIV
我正在尝试从html中删除此空Javascript 反应-从返回条件中删除空DIV,javascript,reactjs,ecmascript-6,Javascript,Reactjs,Ecmascript 6,我正在尝试从html中删除此空 class ParentComp extends Component { ... return ( <div> { GlobalAppHandlerStore.getCurrentState().countryCode === this.props.countryCode ? this.props.children : ''
class ParentComp extends Component {
...
return (
<div>
{
GlobalAppHandlerStore.getCurrentState().countryCode === this.props.countryCode ?
this.props.children
:
''
}
</div>
);
类ParentComp扩展组件{
...
返回(
{
GlobalAppHandlerStore.getCurrentState().countryCode==this.props.countryCode?
这是道具
:
''
}
);
用例:
<ParentComp countryCode={COUNTRY_CODE.be.value}>
<ItemConfigure {...this.props} />
</ParentComp>
如果不匹配,则打印为空。尝试以下操作:
render() {
return GlobalAppHandlerStore.getCurrentState().countryCode === this.props.countryCode && (<div>{this.props.children}</div>);
}
render(){
返回GlobalAppHandlerStore.getCurrentState().countryCode==this.props.countryCode&({this.props.children});
}
试试这个:
render() {
return GlobalAppHandlerStore.getCurrentState().countryCode === this.props.countryCode && (<div>{this.props.children}</div>);
}
render(){
返回GlobalAppHandlerStore.getCurrentState().countryCode==this.props.countryCode&({this.props.children});
}
您能显示您得到的结果的示例以及您希望准确显示的内容吗?在任何情况下,我通常会默认为null
,而不是组件JSX中三元运算符的空字符串。例如:条件?内容:null
,但您只需执行以下操作:GlobalAppHandlerStore.getCurrentState().countryCode==this.props.countryCode&({this.props.children})您能否显示您正在获得的结果的示例以及您希望准确显示的内容?在任何情况下,我通常会将组件JSX中的三元运算符默认为null
,而不是空字符串。例如:condition?Content:null
,但您只需执行以下操作:GlobalAppHandlerStore.getCurrentState().countryCode==this.props.countryCode&({this.props.children})