获取 ObservableHQ 单选按钮的标签

Get the label of an ObservableHQ radio button

有没有办法获取单选按钮的标签?

比如我有

viewof classification = radio({
  options: [
    { label: "Underweight", value: "Underweight" },
    { label: "Healthy Weight", value: "Normal" },
    { label: "Overweight", value: "Overweight" },
    { label: "Obese", value: "Obese" }
  ],
  value: "Underweight"
})

如果我想访问“健康体重”标签而不是“正常”的 classification 值,是否可行?

如果您可以控制收音机的定义(即此收音机不是从您不拥有的笔记本中导入的),您可以对其进行一些重组以使其更容易。

例如在一个单元格中:

options = new Map([
  ["Underweight", "Underweight"],
  ["Normal", "Healthy Weight"],
  ["Overweight", "Overweight"],
  ["Obese", "Obese"]
]);

和无线电小区:

viewof classification = radio({
  options: [...options.entries()].map(([value, label]) => ({label, value})),
  value: "Underweight"
})

并且在单元格中您需要引用标签而不是值:

label = options.get(classification)