javascript - Vue : Rendered list show selected checkboxes

标签 javascript json vue.js rendering

我尝试显示我选择的复选框,我将其呈现如下:

 <pre>{{ JSON.stringify(selectedAttributes, null, 2) }}</pre>
            <ul
              class="list-unstyled"
              v-for="category in categories"
              :key="category.name"
            >
              <strong>{{ category.category_name }} </strong>
              <li
                v-for="attributes in category.attributes"
                :key="attributes.attribute_id"
              >
                <Field
                  as="input"
                  name="attribute"
                  type="checkbox"
                  class="form-check-input"
                  v-model="selectedAttributes"
                  :id="attributes.attribute_id"
                  :value="attributes.attribute_id"
                />
                <label class="form-check-label" for="attributes.attribute_id">
                  {{ attributes.attribute_name }}
                </label>
              </li>
            </ul>

...

  data() {
    return {
      selectedAttributes: [],
    };
  },

不幸的是,我选择的复选框的 attribute_id 没有显示。我的错误在哪里? enter image description here

更新: 来 self 的 api 的数据如下所示:enter image description here

我在这里需要的是,我希望用户检查他的首选选项并在 JSON.stringify 中显示所选选项。 selectedAttributes 应显示所选选项的 attribute_id。

最佳答案

您的数据根本没有 attribute_id id 属性。您只能在您提供的图片中看到attribute_name

关于javascript - Vue : Rendered list show selected checkboxes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70142542/

相关文章:

javascript - Firebug 说 "No Javascript on this page",即使页面上确实存在 JavaScript

android - 指定航路点时,Direction API 仅返回一条路线

javascript - 尝试使用转义的单引号解析JSON时Javascript中的“Unexpected identifier”错误

twitter-bootstrap - 如何在卡组 Bootstrap vue 上设置行中的列?

c# - 将 json 值转换为缺少某些值的数据表

javascript - 如何将 webpack 与静态图像文件一起使用?

javascript - 当导航栏通过单击关闭时,如果单击此类元素,我如何关闭后续链接或执行按钮?

javascript - 'AbortError : The operation was aborted.' - 在 Firefox 中调整 HTML 5 video.currentTime 时出错

javascript - 根据按钮值切换div内容

json - Amazon athena 无法读取 S3 JSON 对象文件,并且 Athena 选择查询返回 JSON 键列的空结果集