有一个递归嵌套的标签:
<list>
<div if="{ items }">
<div each="{ items }">
<input type="checkbox" checked="{ selected }" onclick="{ parent.select }"> {name}
<list />
</div>
</div>
var parent = this.parent
select(e) {
var item = e.item
item.selected = !item.selected
parent.selected = item.selected // does not change parent's checkbox "checked" state
return true
}
</list>
它安装如下:
riot.mount('list', {
items: [
{name: "Item 1"},
{name: "Item 2", selected: true, items: [
{name: "Item 2.1", selected: true, items: [
{name: "Item 2.1.1}
]}
]}
]
})
如标记代码中的注释中所述 - 更改父复选框“已选中”状态时出现问题。但是“选定”属性的值会按预期变化。
是否有可能以某种方式更改父级的复选框状态或为父级标签调用“选择”方法?