显然下面的代码不起作用,老实说,我不知道怎么做。
<div>
<Dropdown labelName="Settings" listItems={[
{name:'View Listing', handlerName:'view_listing'},
{name:'Edit Listing', handlerName:'edit_listing'},
{name:`${this.state.spaceStatus} === 'active' ? 'Deactivate Listing': 'Activate Listing'`, handlerName:'deactivate_listing'},
]}/>
</div>
我可以将我的逻辑排除在外但是试图内联,不确定这是否可行。
答案 0 :(得分:1)
您刚刚结束了模板文字令牌。您的整个条件运算符表达式应位于${...}
中,只需将}
移至'Activate Listing'
结尾后:
<div>
<Dropdown labelName="Settings" listItems={[
{name:'View Listing', handlerName:'view_listing'},
{name:'Edit Listing', handlerName:'edit_listing'},
{name:`${this.state.spaceStatus === 'active' ? 'Deactivate Listing': 'Activate Listing'}`, handlerName:'deactivate_listing'},
// >>>---------------------------------------------------------------------------------^
]}/>
</div>