(求救) ExtJs JsonReader问题...弄了半天也找不到原因 ~~~~ - Web 开发 / Ajax
我用Ext.data.JsonReader 来读取后台的JSON格式数据,为什么STORE就是没有数据呢?
求高手解答啊...
Ext.onReady(function(){ var cm = new Ext.grid.ColumnModel([ {header:'客户',dataIndex:'customsNo',editor:new Ext.grid.GridEditor(new Ext.form.TextField({ allowBlank: false }))}, {header:'订单号',dataIndex:'soNo',editor:new Ext.grid.GridEditor(new Ext.form.TextField({ allowBlank: false }))}, {header:'订单日期',dataIndex:'date',editor:new Ext.grid.GridEditor(new Ext.form.TextField({ allowBlank: false }))}, {header:'订单类型',dataIndex:'type',editor:new Ext.grid.GridEditor(new Ext.form.TextField({ allowBlank: false }))}, {header:'ETA',dataIndex:'eta',editor:new Ext.grid.GridEditor(new Ext.form.TextField({ allowBlank: false }))}, {header:'部门',dataIndex:'department',editor:new Ext.grid.GridEditor(new Ext.form.TextField({ allowBlank: false }))}, {header:'参考号',dataIndex:'ref',editor:new Ext.grid.GridEditor(new Ext.form.TextField({ allowBlank: false }))}, {header:'状态',dataIndex:'status',editor:new Ext.grid.GridEditor(new Ext.form.TextField({ allowBlank: false }))} ]); var store = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({url:"test.jsp"}), reader: new Ext.data.JsonReader({ totalProperty:'totalCount', root:'result' }, [ {name: 'customsNo',type: 'String'}, {name: 'soNo',type: 'String'}, {name: 'date',type: 'String'}, {name: 'type',type: 'String'}, {name: 'eta',type: 'String'}, {name: 'department',type: 'String'}, {name: 'ref',type: 'String'}, {name: 'status',type: 'int'} ]), remoteSort: true }); store.load(); var grid = new Ext.grid.EditorGridPanel({ autoHeight: true, renderTo: 'grid', store: store, loadMask: true, cm: cm, tbar: new Ext.Toolbar([ '-', { text: '删除一行', handler: function(){ Ext.Msg.confirm('信息', '确定要删除?', function(btn){ if (btn == 'yes') { var sm = grid.getSelectionModel(); var cell = sm.getSelectedCell(); var record = store.getAt(cell[0]); store.remove(record); } }); } }, '-', { text: '保存', handler: function(){ var m = store.modified.slice(0); var jsonArray = []; Ext.each(m, function(item) { jsonArray.push(item.data); }); Ext.lib.Ajax.request( 'POST', 'extjs/save.action', {success: function(response){ Ext.Msg.alert('信息', response.responseText, function(){ Ext.Msg.alert('message',response.responseText); }); },failure: function(){ Ext.Msg.alert("错误", "与后台联系的时候出现了问题"); }}, 'data=' + encodeURIComponent(Ext.encode(jsonArray)) ); } }, '-']) });
是不是哪里配错了,或者少配了?
[解决办法]
customsNo:'ss',soNo:'hhh',date:'2010-01-15',type:'保税',eta:'2010-01-15',department:'zzj',ref:'ref',status:'1'
都加引号...
[解决办法]
var store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url:"test.jsp"}),
reader: new Ext.data.JsonReader({
totalProperty:'totalCount',
root:'result'
}, [
{name: 'customsNo',type: 'String'},
{name: 'soNo',type: 'String'},
{name: 'date',type: 'String'},
{name: 'type',type: 'String'},
{name: 'eta',type: 'String'},
{name: 'department',type: 'String'},
{name: 'ref',type: 'String'},
{name: 'status',type: 'int'}
]),
remoteSort: true
});
这段有问题,你把fields放错地方啦!!
[解决办法]
我寫的ds
//讀數據
var ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({ url: 'ASPX/InfoAction.aspx?action=show' }), // MemoryProxy(data),
reader: new Ext.data.JsonReader({
totalProperty: 'totalProperty',
root: 'root'
}, [
{ name: 'action_id' },
{ name: 'action_no' },
{ name: 'action_desc' },
{ name: 'ref_time' }
])
});
lz的參照看看
[解决办法]
{totalCount:2,
result:
[{customsNo:ss,soNo:'hhh',date:'2010-01-15',type:保税,eta:2010-01-15,department:'zzj',ref:'ref',status:'1'},
{customsNo:ss,soNo:'hhh',date:'2010-01-15',type:保税,eta:2010-01-15,department:'zzj',ref:'ref',status:'1'}
]}
格式错误 : customsNo:ss type:保税 eta:2010-01-15
如果直接用eval来转换JSON的话,可以是类似的格式:
{ id:123 , name:"jack",date:"2010-01-15"}
但是有些不是直接用eval来转换的代码,可能认的是非常标准的格式
{ "id":123 , "name":"jack","date":"2010-01-15"}
建议用类似第二种的格式,在哪里都不会错