extjs下拉框,多選,單選,動態傳值


后台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,希望可以幫到需要的人


免責聲明!

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



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