天天看点

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("\",");

 }