0

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

例如我有

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

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

4

1 回答 1

1

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

例如在一个单元格中:

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)
于 2021-10-21T13:22:39.690 回答