admin管理员组文章数量:1023195
I am rendering a page with react and react-bootstrap, with the use of <ListGroup>
and <ListGroupItem>
. The following is my code, and I'm trying to use bsStyle='info'
when the status is not '1'
, and leave it blank when status is '1'
.
<ListGroup>
{tables.map(table => (
<ListGroupItem
key={`table.${table.id}`}
header=(table.name)
bsStyle={table.status !== '1' ? ('info') : ('')}
>
{table.content} -
</ListGroupItem>
))}
</ListGroup>
It rendered properly but keeps getting the following warning due to validation of bsStyle:
Warning: Failed prop type: Invalid prop `bsStyle` of value `` supplied to `ListGroupItem`, expected one of ["success","warning","danger","info"].
There is a workaround to escape the validation by setting bsStyle={null}
. However I can't get it works within the ternary expression. The following code will make it a string bsStyle='{null}'
.
<ListGroup>
{tables.map(table => (
<ListGroupItem
key={`table.${table.id}`}
header=(table.name)
bsStyle={table.status !== '1' ? ('info') : ('{null}')}
>
{table.content} -
</ListGroupItem>
))}
</ListGroup>
What is the proper way to pass {null}
without making it a string?
EDITED: Supposed to be '{null}' and not '{null' up there.
I am rendering a page with react and react-bootstrap, with the use of <ListGroup>
and <ListGroupItem>
. The following is my code, and I'm trying to use bsStyle='info'
when the status is not '1'
, and leave it blank when status is '1'
.
<ListGroup>
{tables.map(table => (
<ListGroupItem
key={`table.${table.id}`}
header=(table.name)
bsStyle={table.status !== '1' ? ('info') : ('')}
>
{table.content} -
</ListGroupItem>
))}
</ListGroup>
It rendered properly but keeps getting the following warning due to validation of bsStyle:
Warning: Failed prop type: Invalid prop `bsStyle` of value `` supplied to `ListGroupItem`, expected one of ["success","warning","danger","info"].
There is a workaround to escape the validation by setting bsStyle={null}
. However I can't get it works within the ternary expression. The following code will make it a string bsStyle='{null}'
.
<ListGroup>
{tables.map(table => (
<ListGroupItem
key={`table.${table.id}`}
header=(table.name)
bsStyle={table.status !== '1' ? ('info') : ('{null}')}
>
{table.content} -
</ListGroupItem>
))}
</ListGroup>
What is the proper way to pass {null}
without making it a string?
EDITED: Supposed to be '{null}' and not '{null' up there.
Share Improve this question edited Jul 3, 2017 at 2:36 Yen Sheng asked Jul 1, 2017 at 16:58 Yen ShengYen Sheng 7251 gold badge14 silver badges28 bronze badges2 Answers
Reset to default 4Your ternary operator's second operand is off:
('{null}')
That evaluates to literally "{null}"
. Try this:
bsStyle={table.status !== '1' ? 'info' : null}
Just use null
plainly, do not wrap it in quotes. Here's a JSFiddle example.
You probably want to ommit whole bsStyle attribute in case status is not different from 1
<ListGroupItem
key={`table.${table.id}`}
header=(table.name)
{...( table.status !== '1' ? {bsStyle:'info'} : {} )}
>
I am rendering a page with react and react-bootstrap, with the use of <ListGroup>
and <ListGroupItem>
. The following is my code, and I'm trying to use bsStyle='info'
when the status is not '1'
, and leave it blank when status is '1'
.
<ListGroup>
{tables.map(table => (
<ListGroupItem
key={`table.${table.id}`}
header=(table.name)
bsStyle={table.status !== '1' ? ('info') : ('')}
>
{table.content} -
</ListGroupItem>
))}
</ListGroup>
It rendered properly but keeps getting the following warning due to validation of bsStyle:
Warning: Failed prop type: Invalid prop `bsStyle` of value `` supplied to `ListGroupItem`, expected one of ["success","warning","danger","info"].
There is a workaround to escape the validation by setting bsStyle={null}
. However I can't get it works within the ternary expression. The following code will make it a string bsStyle='{null}'
.
<ListGroup>
{tables.map(table => (
<ListGroupItem
key={`table.${table.id}`}
header=(table.name)
bsStyle={table.status !== '1' ? ('info') : ('{null}')}
>
{table.content} -
</ListGroupItem>
))}
</ListGroup>
What is the proper way to pass {null}
without making it a string?
EDITED: Supposed to be '{null}' and not '{null' up there.
I am rendering a page with react and react-bootstrap, with the use of <ListGroup>
and <ListGroupItem>
. The following is my code, and I'm trying to use bsStyle='info'
when the status is not '1'
, and leave it blank when status is '1'
.
<ListGroup>
{tables.map(table => (
<ListGroupItem
key={`table.${table.id}`}
header=(table.name)
bsStyle={table.status !== '1' ? ('info') : ('')}
>
{table.content} -
</ListGroupItem>
))}
</ListGroup>
It rendered properly but keeps getting the following warning due to validation of bsStyle:
Warning: Failed prop type: Invalid prop `bsStyle` of value `` supplied to `ListGroupItem`, expected one of ["success","warning","danger","info"].
There is a workaround to escape the validation by setting bsStyle={null}
. However I can't get it works within the ternary expression. The following code will make it a string bsStyle='{null}'
.
<ListGroup>
{tables.map(table => (
<ListGroupItem
key={`table.${table.id}`}
header=(table.name)
bsStyle={table.status !== '1' ? ('info') : ('{null}')}
>
{table.content} -
</ListGroupItem>
))}
</ListGroup>
What is the proper way to pass {null}
without making it a string?
EDITED: Supposed to be '{null}' and not '{null' up there.
Share Improve this question edited Jul 3, 2017 at 2:36 Yen Sheng asked Jul 1, 2017 at 16:58 Yen ShengYen Sheng 7251 gold badge14 silver badges28 bronze badges2 Answers
Reset to default 4Your ternary operator's second operand is off:
('{null}')
That evaluates to literally "{null}"
. Try this:
bsStyle={table.status !== '1' ? 'info' : null}
Just use null
plainly, do not wrap it in quotes. Here's a JSFiddle example.
You probably want to ommit whole bsStyle attribute in case status is not different from 1
<ListGroupItem
key={`table.${table.id}`}
header=(table.name)
{...( table.status !== '1' ? {bsStyle:'info'} : {} )}
>
本文标签: javascriptHow do I use null within a ternary expressionStack Overflow
版权声明:本文标题:javascript - How do I use null within a ternary expression? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745546616a2155422.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论