0
彈簧控制器返回一個json輸出來填充extJs組合框。 我使用spring 3.0.2,並且包含jackson 2.2.3庫。流式json從彈簧返回
控制器類:
@RequestMapping(value="getStates.json", method = RequestMethod.GET)
public @ResponseBody Map<String,? extends Object> loadStates() {
HashMap<String, List<State>> modelMap = new HashMap<String,List<State>>();
modelMap.put("states", stateService.getBrazilianStates());
System.out.println("Returning : " + modelMap.size());
return modelMap;
}
ExtJS的:
Ext.onReady(function(){
var store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'getStates.json'
}),
reader: new Ext.data.JsonReader({
root:'states'
},
[{name: 'code'},
{name: 'name'}
])
});
var combo = new Ext.form.ComboBox({
id: 'statesCombo',
store: store,
displayField: 'name',
valueField: 'code',
hiddenName : 'codeId',
typeAhead: true,
mode: 'local',
fieldLabel: 'States of Brazil',
anchor: '100%',
forceSelection: true,
triggerAction: 'all',
emptyText:'Select a state...',
selectOnFocus:true
});
的組合框下拉卻是空的。
我在做什麼錯?
我預計不需要使用teh @responsebody註釋來指定任何顯式映射。
你確定你的modelMap在控制器中被填充? – shazinltc
是的 - 它確實如此。我不確定如何打印出響應者身份。 – IUnknown
使用curl模擬您「認爲」正在發生的調用,或使用Chrome的開發人員工具或Firefox的Firebug查看正在運行的應用程序的請求/響應對。賠率是,要麼不是你想象的那樣,反應並不包含你認爲它做了什麼,或者你的JS搞砸了一些東西,而且它沒有處理請求的權利。 – CodeChimp