后台java代碼
@RequestMapping(params = "command=adduser")
public void getUser(HttpServletResponse response) throws Exception{
JSONObject result1 = new JSONObject();
JSONArray rows1 = new JSONArray();
String search ="1=1";
List<Inducedcause> list = inducedcauseService.getInducedcauseList(search);
JSONObject ux = null;
for(Inducedcause uc:list){
ux= new JSONObject();
ux.put("id", uc.getId());
ux.put("reason", uc.getReason());
rows1.put(ux);
}
result1.put("results1", rows1);
// result.put("totalCount", list.size());
response.getWriter().write(result1.toString());
}
前台extjs代碼
var comstore1 = new Ext.data.Store(
{proxy: new Ext.data.HttpProxy({url: '${pageContext.request.contextPath}/treatmentrecord/treatmentrecord.page?command=adduser'}),
//讀取json
reader: new Ext.data.JsonReader({
root: 'results1',
remoteSort: true,
fields: ['id','reason']})
});
{
xtype:'lovcombo',
fieldLabel: '誘發原因',
id: 'inducedcause-id',
name: 'inducedcause',
displayField : 'reason',
valueField : 'id',
hiddenName : 'id',
mode : 'local',
editable:false,
loadingText : '加載中...',
store : comstore1,
value:'<%=realname%>',
emptyText:'請選擇原因',
triggerAction : 'all',
maxLength : 100,
multiSelect:true,
anchor:'100%'
},
要實現多選下拉框要引入兩個JS類庫
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/ext/examples/ux/css/Ext.ux.form.LovCombo.css" />
<script type="text/javascript" src="${pageContext.request.contextPath}/ext/examples/ux/Ext.ux.form.LovCombo.js"></script>
否則為單選下拉框,數據是動態的
初學extjs,希望可以幫到需要的人
