如何在 ObservableHQ 的多个单元格中呈现相同的输入元素
How to render the same input element in more cells in ObservableHQ
假设我在 Observablehq 中有以下复选框元素:
viewof myFilter = checkbox({
title: "Foo",
description: "bar",
options: myOptions,
})
我想在笔记本上更多不同的单元格中呈现相同的元素,并且我想同步它们的所有选择。有办法吗?
您似乎在使用 Jeremy Ashkenas 的 venerable inputs library. There’s a newer official Inputs library,它已包含在页面中(您不必导入它)。
官方输入支持使用Inputs.bind
同步(more info)。例如,这两个单元格生成两组同步复选框:
viewof a = Inputs.checkbox(["Foo", "bar"])
Inputs.bind(Inputs.checkbox(["Foo", "bar"]), viewof a)
官方输入复选框 API 大致类似于 Inputs.checkbox(arrayOfChoices, optionsObject)
。没有标题和描述,只有一个标签:Inputs.checkbox(["Foo", "bar"], {label: "Your choice"})
。 More documentation.
假设我在 Observablehq 中有以下复选框元素:
viewof myFilter = checkbox({
title: "Foo",
description: "bar",
options: myOptions,
})
我想在笔记本上更多不同的单元格中呈现相同的元素,并且我想同步它们的所有选择。有办法吗?
您似乎在使用 Jeremy Ashkenas 的 venerable inputs library. There’s a newer official Inputs library,它已包含在页面中(您不必导入它)。
官方输入支持使用Inputs.bind
同步(more info)。例如,这两个单元格生成两组同步复选框:
viewof a = Inputs.checkbox(["Foo", "bar"])
Inputs.bind(Inputs.checkbox(["Foo", "bar"]), viewof a)
官方输入复选框 API 大致类似于 Inputs.checkbox(arrayOfChoices, optionsObject)
。没有标题和描述,只有一个标签:Inputs.checkbox(["Foo", "bar"], {label: "Your choice"})
。 More documentation.