获取表格的特定元素

大家好,我正在尝试在我的表格中获取一个特定元素并向其添加一个类,以便在上传图像时使红色按钮变为绿色。但我无法获得表中的特定行。任何人对此的解决方案?


我的代码:


  <b-table hover

           :filter="filter"

           id="my-table"

           :bordered="bordered"

           :fields="fields"

           :items="items"

           :per-page="perPage"

           :current-page="currentPage"

           responsive

           striped

           small>

    <template v-slot:cell(actions)="row">

      <b-button id="btnImage" size="sm" @click="info(row.item, $event.target)" class="addModal mr-2" ref="addModal">

        <font-awesome-icon :icon="['fas', 'image' ]" />

      </b-button>

    </template>

  </b-table>

如果我这样做: var tr = document.getElementById("my-table").getElementsByTagName("tr"); 我得到以下输出:

http://img4.mukewang.com/6427df080001339119080372.jpg

在每个 tr 中都有一个名为 innerText 的元素,它引用了您可以在我的表格中看到的 id:

http://img.mukewang.com/6427df1c00011c3615760473.jpg

但是如何获取表中的特定行并将类添加到该特定行的按钮?



倚天杖
浏览 92回答 2
2回答

潇湘沐

对于每一个需要它的人。我解决了将 row.item 作为我的方法的参数的问题,非常简单但效果很好

海绵宝宝撒

使用范围字段插槽<template v-slot:cell(nameage)="data">         {{ data.item.name.first }} is {{ data.item.age }} years old       </template>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript