EasyUI combobox 動態下拉列表


 

1.通過<select>元素創建一個預定義結構的下拉列表框。

           <div style="margin-bottom: 10px">
                <label for="accept" class="textbox-label">上級組織名稱</label>
                    <select id="cc2"
                    class="easyui-combobox" name="parent" style="width:400px;" //這里的name  一定是保存的實體類的名字一樣。
                     data-options="panelHeight:70">
                </select>  
            </div>

 

2.使用Javascript創建下拉列表框。

$("#cc2").combobox ({
            editable : false,
            url : "/org/getOrgName ",//url
            valueField : "id", //相當於 option 中的 value 發送到后台的
            textField : "orgName"//option中間的內容 顯示給用戶看的
        });
       

后台數據:

1.創建一個vo

package com.xintouyun.duchaban.bean;

public interface GetOrgNameVo {
    String getId();
    String getOrgName();//組織名

}

 

2.repo層

package com.xintouyun.duchaban.repo;

import java.io.Serializable;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;


import com.xintouyun.duchaban.bean.GetOrgNameVo;


import com.xintouyun.duchaban.entity.SysOrg;

public interface SysOrgRepo extends JpaRepository<SysOrg, Serializable> {

    @Query(value = " from SysOrg  ")
    List<GetOrgNameVo> findByid();

}

 

3.service 層

package com.xintouyun.duchaban.service;

import java.util.List;

import com.xintouyun.duchaban.bean.GetOrgNameVo;

public interface SysOrgService {
        
        List<GetOrgNameVo> getOrgName();

}

4.serviceImpl 層

package com.xintouyun.duchaban.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.xintouyun.duchaban.bean.GetOrgNameVo;
import com.xintouyun.duchaban.bean.SysOrgVo;

import com.xintouyun.duchaban.repo.SysOrgRepo;

import com.xintouyun.duchaban.service.SysOrgService;

@Service
@Transactional
public class SysOrgServiceImpl implements SysOrgService {

    @Autowired
    private SysOrgRepo orgRepo;
    
 
    @Override
public List<GetOrgNameVo> getOrgName() {
    
    return orgRepo.findByid();
}




}

5. controller 層

package com.xintouyun.duchaban.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.xintouyun.duchaban.bean.GetOrgNameVo;
import com.xintouyun.duchaban.service.SysOrgService;

@Controller
@RequestMapping("/org")

public class SysOrgController {
    @Autowired
    private SysOrgService OrgService;
   

    @PostMapping("/getOrgName")
    @ResponseBody
    public  List<GetOrgNameVo> getOrgName(){
         return OrgService.getOrgName();
    
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM