zoukankan      html  css  js  c++  java
  • vue+element 多个checkbox+select思路及方式

    HTML:

    <el-checkbox-group v-model="re_hotel" class="col-padding">
                      <el-col v-for="(hotel_item, hotel_id) in all_hotel_room" :key="hotel_id" :span="8">
                        <el-checkbox :label="hotel_id" @change="(param) => { return check_hotel_new(hotel_item, hotel_id, param) }">{{ hotel_item.name }}</el-checkbox>
                        <el-select v-model="re_room[hotel_id]" multiple collapse-tags placeholder="全部房型" @change="(param) => { return update_room_select(param, hotel_id)}">
                          <el-option
                            v-for="(room_item, room_id) in hotel_item.room_type"
                            :key="room_id"
                            :label="room_item.room_name"
                            :value="room_item.room_id"
                          />
                        </el-select>
                      </el-col>
                    </el-checkbox-group>
    

     data:

    all_hotel_room: {},
          re_hotel: [],
          re_room: {},
          form_apply_room_types: [],
    

     js:

    初始化数据为id对象
    getHotelRoomType().then(res => {
            if (res.code === 0) {
              // 初始化房型为id对象
    
              for (let i = 0; i < res.data.length; i++) {
                if (res.data[i].room_type.length > 0) {
                  // this.room_type[i] = []
                  this.hotel_room_data[res.data[i].hotel_id] = res.data[i]
                  this.all_hotel_room[res.data[i].hotel_id] = res.data[i]
                  this.re_room[res.data[i].hotel_id] = []
                }
              }
              console.log('all_hotel_room', this.all_hotel_room)
              console.log('-----', this.hotel_room_data)
              for (let i = 0; i < res.data.length; i++) {
                if (res.data[i].room_type.length > 0) {
                  // this.room_type[i] = []
                  this.room_type[res.data[i].hotel_id] = []
                }
              }
              console.log(this.room_type)
              res.data.forEach(v => {
                if (v.room_type.length > 0) {
                  this.ruleForm.apply_room_types.push(v)
                  this.apply_room_new.push(v)
                }
              })
            }
          })
    

     处理点击checkbox数据:

    check_hotel_new(hotel_item, hotel_id, param) {
          if (param) {
            var room_type = hotel_item.room_type
    
            var roomidArr = []
            for (let i = 0; i < room_type.length; i++) {
              roomidArr.push(room_type[i].room_id)
            }
            this.re_room[hotel_id] = roomidArr
          } else {
            this.re_room[hotel_id] = []
          }
    
          console.log(hotel_item, hotel_id, this.re_room)
        }
    

     提交的时候转化为对象:

    var all_room_types = []
          this.form_apply_room_types = []
          Object.keys(this.re_room).forEach(hotel_id => {
            if (this.re_room[hotel_id].length) {
              this.form_apply_room_types.push({
                'hotel_id': Number(hotel_id),
                'room_type': this.re_room[hotel_id]
              })
            }
    
            all_room_types.push(this.re_room[hotel_id])
          })
    
  • 相关阅读:
    Cross-Site Scripting(XSS)简介
    nginx查看安装了哪些模块
    Win7系统修改hosts文件不能保存的解决方法
    firefox怎么修改tls协议号
    在Nginx中部署基于IP的虚拟主机
    openssl生成ssl证书
    给kali linux2.0装一个中文输入法
    tenda u1 usb wireless device install driver for kali linux kernal Debian 4.3.3-7kali2 (2016-01-27) x86_64 GNU/Linux
    python2.7.x的字符串编码到底什么鬼?(中文和英文的处理)
    fswatch rsync配置使用 rsync 传输大量细小文件
  • 原文地址:https://www.cnblogs.com/zhpblog/p/14973715.html
Copyright © 2011-2022 走看看