ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

nuxt项目表格多选table,input传参并选中input type=“checkbox“原生js

2022-01-19 17:02:13  阅读:174  来源: 互联网

标签:传参 checkbox Name width itemArr item input Quantity Description


<template>

<div class="dist-content">

        <form :model="form">

          <table>

            <thead>

              <tr style="text-align: left">

                <th class="th">Name</th>

                <th class="th">Description</th>

                <th class="th">Quantity</th>

              </tr>

            </thead>

            <tbody>

              <tr v-for="(item, index) in ExampleData" :key="index">

                <td class="checkbox">

                  <label>

                    //v-model所带的值为是否选中,:name所带的值为参数

                    <input

                      v-model="item.isSelect"

                      :name="item.Name+ '%' + item.Description+ '%' + item.Quantity"

                      type="checkbox"

                      style="margin-right: 6px"

                      @click="IsCheck"

                    />

                    {{ item.Name}}

                  </label>

                </td>

                <td>{{ item.Description}}</td>

                <td>{{ item.Quantity}}</td>

              </tr>

            </tbody>

          </table>

        </div>

</form>

</template>

<script>

export default {

        data() {

                return {

                       ExampleData:[

                               

{

            Name: '1',

            Description: 'one',

            Quantity: '1',

          },

          {

            Name: '2',

            Description: 'two',

            Quantity: '2',

          },

          {

            Name: '3',

            Description: 'three',

            Quantity: '3',

          }

                        ],

                Form:{

                           SelectedData  :[],                        

                        }

                }        

        },

methods: {        

IsCheck(e) {

        let itemArr = [];

        const _this = this;

        const ExampleData= _this.ExampleData;

        itemArr = e.target.name.split('%');

        const itemStr = { Name: itemArr[0], Description: itemArr[1], Quantity: itemArr[2]};

        this.Form.SelectedData  = [];

        //和原数据进行对比

        const select = ExampleData.find((d) => {

          return d.Name=== itemStr.Name&& d.Description=== itemStr.Description&& d.Quantity=== itemStr.Quantity;

        });

        //select 为选中的对象,在选中的对象里添加select字段

        select.isSelect = e.target.checked;

        ExampleData.forEach((e) => {

          if (e.isSelect) {

            // 选中数组

            this.Form.SelectedData .push({ Name: e.Name, Description: e.Description, Quantity: e.Quantity });

        console.log(this.Form.SelectedData)//该数组可作为接下来要请求接口传参数

          }

        });

      },

}

}

</script>

<style lang="scss">

        

.dist-content {

        height: 246px;

        padding: 12px;

        overflow-y: auto;

        border: 1px solid #ccc;

        @media (max-width: 600px) {

          height: auto;

        }

        table {

          td {

            padding: 6px 0;

          }

          .th {

            width: calc(100% / 2.5);

            overflow: hidden;

            text-overflow:ellipsis;

            white-space: nowrap;

            @media (max-width: 600px) {

              &:nth-child(1) {

                padding-right: 20px;

              }

              &:nth-child(3) {

                display: none;

              }

            }

          }

          tbody {

            .checkbox {

              line-height: 12px;

              cursor: pointer;

              @media (max-width: 600px) {

                padding-right: 20px;

              }

            }

            td:nth-child(1){

              &:hover {

                color: #1c449b;

                cursor: pointer;

              }

            }

            @media (max-width: 600px) {

              td:nth-child(3) {

                display: none;

              }

            }

          }

        }

      }

</style>

标签:传参,checkbox,Name,width,itemArr,item,input,Quantity,Description
来源: https://blog.csdn.net/zhongli_/article/details/122583682

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有