原文是根据这里看的https://blog.csdn.net/weixin_43859703/article/details/109826671
看完之后很受启发,因为这个这个之前没有用过,附上我自己写的代码,希望对你们有用
<Switch defaultChecked={() => {
console.log(item.timing_effective)
if (item.timing_effective == 1) { return true }
if (item.timing_effective == 0) { return false }
}}
key={item.timing_effective}
onChange={() => {
if (item.timing_effective == 1) {
sdk.controlDeviceData({ "num_down": item.num_down, "timing_effective": 0 })
sdk.controlDeviceData({ "get_timed_task": 1 })
} else {
sdk.controlDeviceData({ "num_down": item.num_down, "timing_effective": 1, "power_switch": item.power_switch, "time_down": item.time_down, "week_down": item.week_down })
sdk.controlDeviceData({ "get_timed_task": 1 })
}
}}></Switch>