我想呈现一个 HTML 复选框,其选中状态由数据控制。
给一个接收item
类型的无状态组件{ label: string, checked: bool}
,
像这样:
let component = ReasonReact.statelessComponent("TodoItem");
let make = (~item, _children) => {
render: _self => {
<li> <input type_="checkbox" {/*looking for something like this*/ item.checked ? "checked" : "" /* doesn't compile */}/> {ReasonReact.string(item.label)} </li>
}
}
如何根据条件将属性的存在添加checked
到input
标签中item.checked == true
?