Conditionally set an object property

后端 未结 6 1960
太阳男子
太阳男子 2020-12-04 17:37

Is there some syntax for setting properties based on a condition?

data: {
    userId: 7,
    actionId: 36,
    express: (myCondition ? true : null) // does n         


        
6条回答
  •  一整个雨季
    2020-12-04 18:25

    first of all, thats javascript, not JSON.

    the solution:

    data: {
        userId: 7,
        actionId: 36
    }
    if(myCondition) data["express"] = true;
    

提交回复
热议问题