两个Select选择器实现联动(vue+element)

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

1.需求:点击某个设备组获取该设备组的所有的商品。

2.效果图:

两个Select选择器实现联动(vue+element)_第1张图片

两个Select选择器实现联动(vue+element)_第2张图片

3.实现:

(1)前端


      
    
    
      
    
//进入列表时先获取所有的设备组   
getAllDevice(){//获取所有的设备组
      getAllDevice()
        .then(response =>{
          this.deviceGroups = response;
        })
    },   

selectGoodsByGroupId(val){//根据设备组id获取相应的商品
      //console.log(val);
      if(val != null && val != '' && val != undefined){
        selectGoodsByGroupId(val)
          .then(response => {
            //给goods数组赋值
            this.goods = response;
          })
      }
    },

(2)后端

1.controller层

/**
     * 根据设备组Id进行获取商品Id进而查询对应的商品信息
     * @param groupId
     * @return
     */
    @RequestMapping(value = "/selectGoodsByGroupId/{groupId}",method = RequestMethod.GET)
    @ResponseBody
    public List selectGoodsByGroupId(@PathVariable("groupId") int groupId){
        return baseBiz.selectGoodsByGroupId(groupId);
    }

2.biz层

/**
     * 根据设备组Id进行获取商品Id进而查询对应的商品信息
     * @param groupId
     * @return
     */
    public List selectGoodsByGroupId(int groupId){
        return mapper.selectGoodsByGroupId(groupId);
    }

3.mapper层

/**
     * 根据设备组Id进行获取商品Id进而查询对应的商品信息
     * @param groupId
     * @return
     */
    List selectGoodsByGroupId(@Param("groupId") int groupId);

4.mybatis.xml


    

 

转载于:https://my.oschina.net/u/3734228/blog/3046041

你可能感兴趣的:(两个Select选择器实现联动(vue+element))