这是extjs的代码
Ext.regModel('User',{
fields:[
{name: 'appeId'},
{name: 'survId'},
{name: 'location'},
{name: 'surveyDate'},
{name: 'surveyTime'},
{name: 'inputUserId'}
]
});
var proxy=new Ext.data.proxy.Ajax({
type:'ajax',
url:'survey.html'
});
//构建Store
var store=new Ext.data.Store({
proxy:proxy,
model:'User',
autoLoad: true,
render:'json'
});
store.add({appeId:'qwe',survId:'123',location:'123',surveyDate:'s',surveyTime:'s',inputUserId:'s'});
store.sync();
//载入
store.load();
// create the grid
var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{text: "appeId", width: 60, dataIndex: 'appeId', sortable: true},
{text: "survId", width: 60, dataIndex: 'survId', sortable: true},
{text: "location", width: 60, dataIndex: 'location', sortable: true},
{text: "surveyDate", width: 100, dataIndex: 'surveyDate', sortable: true},
{text: "surveyTime", width: 100, dataIndex: 'surveyTime', sortable: true},
{text: "inputUserId", width:80, dataIndex: 'inputUserId', sortable: true}
],
renderTo:'example-grid',
width:540,
height:200
});
这是survey.html
[{"appeId":"1","survId":"1","location":"","surveyDate":"2008-03-14","surveyTime":"12:19:47","inputUserId":"1","inputTime":"2008-03-14
12:21:51","modifyTime":"0000-00-0000:00:00"}]
值传不过来啊,store.add 自己添加的能显示出来。
你怎么返回的,是通过response.getWriter().println返回的吗
不是的,我是生成json了。不过解决了,是json格式的问题,之前改了我忘记了。谢谢!
你的reader可以读出你发出来的这个数据。你的是html静态页面,注意不要用post请求,有些服务器静态页面是不允许post请求的
而且你store已经配置为autoLoad就不需要在调用load方法了
private String getResponseText(Object content){
ObjectMapper mapper = new ObjectMapper();
try {
System.out.println(content.toString());
return mapper.writeValueAsString(content);
} catch (JsonGenerationException e) {
//logger.error("JsonGenerationException "+e.getLocalizedMessage());
e.printStackTrace();
} catch (JsonMappingException e) {
//logger.error("JsonMappingException "+e.getLocalizedMessage());
e.printStackTrace();
} catch (IOException e) {
//logger.error("IOException "+e.getLocalizedMessage());
e.printStackTrace();
}
return null;
}