Ext combo無法載入後臺store
阿新 • • 發佈:2018-12-14
Ext.define('Beam', { extend: 'Ext.data.Model', fields: [ {name: 'id', type: 'int'}, {name: 'name', type: 'string'}, ] }); var beamSearch = Ext.create('Ext.data.Store', { model: 'Beam', proxy: { type: 'ajax', api:{ read:'../loadBeamStore.action' }, reader: { type: 'json', root: 'beams' } }, autoLoad: false });
combo內容如下
{ xtype:'combo', fieldLabel: '名稱', store: beamSearch, itemId:'beamSearch', queryMode: 'local', displayField: 'name', valueField: 'id', forceSelection:true, editable : false, hideTrigger : false,// 隱藏微調按鈕 allowBlank : false, value:0, listeners:{ 'expand':function(th){ beamSearch.load(); } } }
後臺action若定義了success變數,則前端返回的success必須設為true,否則無法加載出store。
private List<Beam> beams = new ArrayList<Beam>(); private boolean success;//定義了success變數 @Action(value = "loadBeamStore", results = { @Result(type = "json") }) public String loadBeamStore(){ int num = 23; for(int i = 1; i < num; i++){ Beam beam = new Beam(); beam.setId(i); beam.setName("option "+i); beams.add(beam); } this.success = true;//則必須返回true return SUCCESS; }