在下面的API文件数据中,
- 如果"brightness_value"大于0,我想将模式设置为"turn_on"。**
- 如果亮度值为0,我想将模式设置为"turn_off"。**
这有可能实现吗?
如果是,如何做到?
- API文件**
Method: POST
URL: xxx.com
Data:
{
"time_start":"16:20",
"time_end":"16:21",
"mode":{
"mode":"turn_off", //or “turn_on”
"rgb_color":[255,255,255],
"brightness":50
}
}
- 我的React.js代码**
const [brightness_value, setBrightnessValue] = useState();
const setSchedule = async(data) => {
await axios.post('xxx.com',
{
time_start: "16:20",
time_end: "16:21",
mode: {
mode: "turn_off",
rgb_color: [255,255,255],
brightness: brightness_value,
}
},
{
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${cookies.get('accesstoken')}`
},
})
.then(result => {
console.log('Scheduled!');
})
.catch(err => {
console.log(err);
console.log('Missed Schedule!');
});
}
3条答案
按热度按时间1wnzp6jl1#
使用三元运算符执行以下操作:
9udxz4iz2#
只需在此处添加条件
xfb7svmp3#
它应该能完成任务。