天天看點

easyui datagrid combobox通過url擷取json資料的下拉框

------前台部分------------

<th align="left" width="12%" data-options="field:'relationtype',

formatter: function(value,row){

var dicname;

$.ajax(            //這是選中後傳回的名稱,沒有這一步就會出現,選中離開後,還是原來的名稱。

             {

               type: 'post',

               url: '${path }/tfieldTypeAction!getDICName.do',

               data: 'dicValue='+value,

               async:false, //必須,不然外部js無法擷取内容

               dataType: 'text',

               success: function (result) {

                   dicname=result;

               },

               error: function (err) {

                   alert('error'+err);

                   return false;

               }

           });

           return dicname;

                               },

editor:{

type:'combobox',

options:{

valueField:'value',

textField:'name',

url:'${path }/tfieldTypeAction!getrelationtypeByMarkDCList.do',

editable:false,

required:true}

}">資料關聯</th> 

------背景json部分-------

//json

public void getrelationtypeByMarkDCList()  

{

try {

HttpServletResponse response = ServletActionContext.getResponse();

response.setContentType("application/json");

response.setCharacterEncoding("UTF-8");

try {

creditRelationTypeList = wfDataDicImpl.getByMarkDCList(DictionaryID.RELATION_TYPE);

 jsonArray = JSONArray.fromObject( creditRelationTypeList );

} catch (Exception e) {

e.printStackTrace();

}

response.getWriter().write(jsonArray.toString());// 傳回json類型對象

response.getWriter().close();

} catch (IOException e) {

e.printStackTrace();

}

}

public void getDICName()

{

String dicname="";

HttpServletResponse response = ServletActionContext.getResponse();

response.setContentType("application/json");

response.setCharacterEncoding("UTF-8");

try {

if (!StringUtils.isEmptyOrNull(dicValue)) {

List<WfDataDic> wfdatadiclist = wfDataDicImpl

.getByMarkDCList(DictionaryID.RELATION_TYPE);

for (WfDataDic wfDataDic : wfdatadiclist) {

if (dicValue.equals(wfDataDic.getValue())) {

 dicname=wfDataDic.getName();

}

}

response.getWriter().write(dicname);

response.getWriter().close();

}

} catch (IOException e) {

e.printStackTrace();

}catch (Exception e) {

e.printStackTrace();

}

}

--------擷取節點部分-------

if(!StringUtils.isEmptyOrNull(lc.getRelationtype()))

 {

 sb.append("\"relationtype\":\""+lc.getRelationtype()).append("\",");

 }