【发布时间】:2021-10-30 01:38:09
【问题描述】:
正在调试,但不确定此结构是否有效...
onClick={()=>{ //2. an image is clicked, and the choice is added to the choiceOrder state, and then a jsonupdate is called -- 3. in ChooseBy.js
//onclick, add or remove the choice
choosebyprops.setChoiceOrder( choiceOrder=>
choiceOrder.includes(attrprops.attrChoice)
?
(
(choiceIndex = choiceOrder.findIndex(attrprops.attrChoice)),
(choiceOrder.filter(list=> list!==attrprops.attrChoice)),
(choosebyprops.setJsonList(jsonList=> jsonList.splice(choiceIndex) )) //removes the json data for that choice
)
:
(
( [...choiceOrder,attrprops.attrChoice] ),
(choosebyprops.setJsonList(jsonList=> [...jsonList, UpdateJson({...allprops})])) //adds json data for that choice
)
)
}}
我基本上是在尝试制作一个 json 列表,如果我点击按钮,过滤后的 json 会添加到该选项的列表中,如果我取消点击它,它就会被删除。
但我只是想知道我是否可以在该三元函数中包含多个语句。
【问题讨论】:
标签: javascript reactjs next.js