javascript - 如何使用vuejs在每一行显示复选框

标签 javascript vue.js

如何使用vuejs在每一行中显示复选框,我需要将这些选中的项目传递给函数以进行进一步处理。 我尝试过但无法正常工作。我在下面给出了带有 api 数据输出的代码。

我需要将选定的 id 传递给 on()。

        <va-card style="margin-top:20px">
         <table  style="width:100%;border:2px">
                <thead>
                  <tr>
                    <th>Pole ID</th>
                    <th>Address</th>
                   <th>     
                    <label class="form-checkbox">
                      <input type="checkbox" v-model="selectPole"  >
                      <i class="form-icon"></i>
                    </label>
                  </th>
                  </tr>
                </thead>
                <tbody>
                <tr v-for="pole in streetInfo">
                  <td style="font-weight:bold">{{pole.pole}}</td>
                 <td>{{pole.address}}</td>
                  <td>       
                   <label class="form-checkbox">
                  <input type="checkbox" :value="pole.pole" v-model="selectedStreetLight">
                <i class="form-icon"></i>
                </label>
              </td>
             </tr>
           <va-button  @click="On()" class="my-0">ON</va-button>
            <va-button   @click="Off()" class="my-0">OFF</va-button>
            </tbody>
           </table>
          </va-table>
       </va-card>

//api数据输出

        [
          {
            "address": "Jayanagar 4th Block Banglore", 
            "pole": "BNG-JAY-137-003",
            "select":false
          }, 
          {
            "address": "Jayanagar 5th Block Banglore", 
            "pole": "BNG-JAY-137-004",
            "select":false
          }, 
          {
            "address": "Jayanagar 6th Block Banglore", 
            "pole": "BNG-JAY-137-005",
            "select":false
          }
        ]

最佳答案

        <tr v-for="(index,pole) in streetInfo">
          <td style="font-weight:bold">{{pole.pole}}</td>
         <td>{{pole.address}}</td>
          <td>       
           <label class="form-checkbox">
          <input @change="change(index)" type="checkbox" :value="pole.pole" v-model="selectedStreetLight">
        <i class="form-icon"></i>
        </label>
      </td>

这里我改变了streetInfo中的(index,pole)@change="change(index)

并进行更改(索引)方法并放置您想要的内容。

change(index)
{
    this.streetInfo[index].select=!this.streetInfo[index].select;
}

我相信这会有所帮助

关于javascript - 如何使用vuejs在每一行显示复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58407916/

相关文章:

javascript - 为不使用 Vue 的网格注入(inject)浏览器前缀

ecmascript-6 - Electron & ES6 在使用 gulp 和 ES6 模块时如何实现 require remote/ipc

javascript - 从 Vue 的生产构建中删除选定的路由

javascript - 火存储 : onWrite Convert Keywords Array String to Lower Case Items

javascript - jquery ui 自动完成的绝对路径

javascript - 带有输出百分比的jquery自定义字符串比较函数

javascript - .net 中的日期与 javascript 中的日期

javascript - 将网页 B 的部分插入到网页 A

javascript - 如何在我的 Vue 项目中设置 vue-burger-menu

laravel-5 - 单击浏览器的后退 <- 按钮时,Json 将显示在 Vue 组件上