---
title: "struts2 easyui combobox"
author: "atgoingguoat"
date: "2014-05-27T15:32:22Z"
tags: ["Struts2", "combobox", "easyui", "下拉框"]
categories: ["Web前端"]
slug: "struts2-easyui-combobox"
draft: false
lastmod: "2014-05-27T15:35:25Z"
id: 2072152
url: "https://atgoingguoat.iteye.com/blog/2072152"
---

今天花了半天才搞定。

网上找了不少例子。最后搞定了。

 效果图  
![](http://dl2.iteye.com/upload/attachment/0097/5447/96370320-396e-3b02-b9f6-a02a79bae778.jpg)  
 

&lt;input id="wifis\_barId\_index" class="easyui-combobox"  /&gt;

 

/\*\*下拉框初始化\*/

from\_initUserCombox();

function from\_initUserCombox() {

$.ajax({  

url:"barapp/Bars/getComboBox.do",

 cache: false,  

 dataType:"json",  

 success: function(result){

 //alert("ok"+result.list\[0].id);

 var feiqumingxiarr = new Array();

 feiqumingxiarr =result.list;

   $("#wifis\_barId\_index").combobox({  

       data : feiqumingxiarr,  

       valueField : 'id',  

       textField : 'name' 

   });  

 },

 error : function(){

 alert("error");

 }

});

//$("#wifis\_barId\_index").combobox({

  //url:"barapp/Bars/getComboBox.do",

   //valueField:'id',

   //textField:''

//});

}

 

后台返回JSON串

{"list":\[{"annexList":\[],"city":"长沙","explains":"诞集团。","id":1,"idList":\[],"logPic":"http://117.40.178.58:7070/bar/upload/bar/1.jpg","name":"苏荷酒吧","password":"888888","tel":"13786141175"},{"annexList":\[],"city":"长沙","explains":"分为演艺吧。","id":2,"idList":\[],"logPic":"http://117.40.178.58:7070/bar/upload/bar/2.jpg","name":"魅力四射","password":"888888","tel":"0731-85171988"}],"success":false}

 

/\**

\*  &lt;p&gt;标题：下拉框所用 列表 

\* @throws IOException

\*/

public void getComboBox() throws IOException { 

Map&lt;String, Object&gt; result = new HashMap&lt;String, Object&gt;();

List list = new ArrayList();

try {

String str = "";

Bars barsobj = new Bars();

list = barsManager.findAll();

       result.put("success", false);

       result.put("list", list);

} catch (Exception e) { 

e.printStackTrace();

}

outJson(result);

}