三級下拉選

1、建表

image.png

一級下拉選沒有father_id,二級下拉選的father_id是一級下拉選的id,三級下拉選的father_id是二級下拉選的id,以此類推。 2、SQL

<!-- 報修工單 1級下拉選-->
      <select id="findFirst1" resultMap="BaseResultMap">
          SELECT
                id,
                "name",
                father_id
          FROM
                out_dictionary
          WHERE
              father_id IS NULL
    </select>
    <!-- 報修工單 2級下拉選-->
    <select id="findSecond2" resultMap="BaseResultMap">
        SELECT  
            id,
            "name" ,
            "type",
            father_id  
        FROM  
            out_dictionary  
        WHERE  
            father_id =#{fatherId}
    </select>
    <!-- 報修工單 3級下拉選-->
    <select id="findThird3" resultMap="BaseResultMap">
        SELECT  
            id,
            "name",
            "type",
            father_id  
        FROM  
            out_dictionary  
        WHERE  
            father_id =#{fatherId}
    </select>

3、Dao、Service

/**
     * 報修工單 一級下拉選
     * @param domainId
     * @return
     */
    List<OutDictionary> findFirst1();
    /**
     * 報修工單 二級下拉選
     * @param fatherId
     * @return
     */
    List<OutDictionary> findSecond2(Integer fatherId);
    /**
     * 報修工單 三級下拉選
     * @param fatherId
     * @return
     */
    List<OutDictionary> findThird3(Integer fatherId);

4、impl

@Autowired
    private OutDictionaryDao OutDictionaryMapper;

    //報修工單 一級下拉選
    @Override
    public List<OutDictionary> findFirst1() {
        
        return OutDictionaryMapper.findFirst1();
    }
    //報修工單 二級下拉選
    @Override
    public List<OutDictionary> findSecond2(Integer fatherId) {
        
        return OutDictionaryMapper.findSecond2(fatherId);
    }
    //報修工單 三級下拉選
    @Override
    public List<OutDictionary> findThird3(Integer fatherId) {
        
        return OutDictionaryMapper.findThird3(fatherId);
    }

5、Controller層

/**
         * 報修工單一級下拉選
         * @param req
         * @return
         */
        @RequestMapping(value = "/inFirst1", method = RequestMethod.POST)
        @ResponseBody
        public JSONArray inFirst1( HttpServletRequest   req) {
           //Integer domainId =  Integer.parseInt(req.getSession().getAttribute("domainId").toString());
            List<OutDictionary> first = outDictionaryService.findFirst1();
            JSONArray jsonArr = JSONArray.fromObject(first);
            return jsonArr;
        }
        /**
         * 報修工單二級下拉選
         * @param req
         * @return
         */
        @RequestMapping(value = "/inSecond2", method = RequestMethod.POST)
        @ResponseBody
        public JSONArray inSecond2(Integer fatherId,HttpServletRequest   req) {
            //Integer domainId =  Integer.parseInt(req.getSession().getAttribute("domainId").toString());
            List<OutDictionary> second = outDictionaryService.findSecond2(fatherId);
            JSONArray jsonArr = JSONArray.fromObject(second);
            return jsonArr;
        }
        /**
         * 報修工單三級下拉選
         * @return
         */
        @RequestMapping(value = "/inThird3", method = RequestMethod.POST)
        @ResponseBody
        public JSONArray inThird3(Integer fatherId,HttpServletRequest   req) {
            //Integer domainId =  Integer.parseInt(req.getSession().getAttribute("domainId").toString());
            List<OutDictionary> third = outDictionaryService.findThird3(fatherId);
            JSONArray jsonArr = JSONArray.fromObject(third);
            return jsonArr;
        }

6、JS

//一二三級分類  下拉選
        $('#select_first_rep').combobox({
                    url : '${path }' + '/dictionary/inFirst1',
                    valueField : 'id',
                    textField : 'name',
                    onSelect : function() {
                        var xqmc = $('#select_first_rep').combobox('getText');//獲取當前選中的
                        var pccode = $('#select_first_rep').combobox('getValues')[0];//獲取當前選
                        $('#select_second_rep').combobox({
                             url : '${path }'+'/dictionary/inSecond2?fatherId='+pccode,
                             valueField : 'id',
                             textField : 'name',
                             onSelect : function() {
                                var pccode1 = $('#select_second_rep').combobox('getValues');
                                var fId;
                                if(pccode1!=null){
                                    fId=pccode1[0];
                                }
                                $('#select_third_rep').combobox({
                                    url : '${path }'+'/dictionary/inThird3?fatherId='+fId,
                                     valueField : 'id',
                                     textField : 'name',
                                     onSelect : function() {}
                                     }) 
                             }
                             })
                    }
        })
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章