ExtJS gird从后台springmvc获取数据
Extjs的gird从后台请求数据。后台java类成功收到了请求,准备了数据。但是如何把数据传给刚才的extjs页面中的store。index.jsp页面:varPlan...
Extjs的gird从后台请求数据。后台java类成功收到了请求,准备了数据。但是如何把数据传给刚才的extjs页面中的store。
index.jsp页面:
var Plant = Ext.data.Record.create([
{name: 'id', type: 'int'},
{name: 'name', type: 'string'},
{name: 'desc',type:'string'},
{name: 'sex', type: 'string'}
]);
var ds = new Ext.data.Store({
url: '${ctp}/panel/panel2',
reader: new Ext.data.JsonReader({
root:"userList"
}, Plant)
});
ds.load();
后台java类UserController:
@RequestMapping("/panel2")
public void toPanel2(Model model){
System.out.println("---method:panel2");
List<User> userList=new ArrayList<User>();
User user1=new User(1,"name1","desc1","sex1");
User user2=new User(2,"name2","desc2","sex2");
userList.add(user1);
userList.add(user2);
model.addAttribute(userList);
Map<String, Object> hm = new HashMap<String,Object>();
hm.put("userList", userList);
System.out.println(hm);
model.addAttribute(hm);
}
注:程序已经成功执行到了后台这个方法中,我把数据保存到了userList中。
求助:后台如何把数据返回给刚才的Index.jsp页面中的store?好让它能够得到数据。 展开
index.jsp页面:
var Plant = Ext.data.Record.create([
{name: 'id', type: 'int'},
{name: 'name', type: 'string'},
{name: 'desc',type:'string'},
{name: 'sex', type: 'string'}
]);
var ds = new Ext.data.Store({
url: '${ctp}/panel/panel2',
reader: new Ext.data.JsonReader({
root:"userList"
}, Plant)
});
ds.load();
后台java类UserController:
@RequestMapping("/panel2")
public void toPanel2(Model model){
System.out.println("---method:panel2");
List<User> userList=new ArrayList<User>();
User user1=new User(1,"name1","desc1","sex1");
User user2=new User(2,"name2","desc2","sex2");
userList.add(user1);
userList.add(user2);
model.addAttribute(userList);
Map<String, Object> hm = new HashMap<String,Object>();
hm.put("userList", userList);
System.out.println(hm);
model.addAttribute(hm);
}
注:程序已经成功执行到了后台这个方法中,我把数据保存到了userList中。
求助:后台如何把数据返回给刚才的Index.jsp页面中的store?好让它能够得到数据。 展开
展开全部
你好!
只需要在方法上添加注解@ResponseBody再修改方法的返回值即可。
参考下面代码:
@ResponseBody
@RequestMapping("/panel2")
public Map<String, Object> toPanel2(Model model){
System.out.println("---method:panel2");
List<User> userList=new ArrayList<User>();
User user1=new User(1,"name1","desc1","sex1");
User user2=new User(2,"name2","desc2","sex2");
userList.add(user1);
userList.add(user2);
model.addAttribute(userList);
Map<String, Object> hm = new HashMap<String,Object>();
hm.put("userList", userList);
System.out.println(hm);
//model.addAttribute(hm);
return hm;
}
希望对你有帮助!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询