实在没办法了ext grid不显示数据啊

ma1986 2011-09-07 03:10:08
var store = Ext.create('Ext.data.Store', {

model:'Task',
proxy : new Ext.data.HttpProxy({
url : 'detail_qurey.asp?projectid='+projectid, //说明后台的serverlet
method : 'POST'
}),

reader : new Ext.data.JsonReader({
root : "rows",
totalProperty : 'total',
id: 'itemid'
},Task), //说明数据结构

sortInfo : {property: 'itemid', direction: 'ASC'},
groupField: 'bigitem'
});
store.load({
scope : store ,
callback: function(records, operation, success) {
if (success) {
alert(records.length);
}
}
});
我不知道为什么不显示数据,alert(records.length)为1,在firebug里面查看json是有的啊
{"rows":[{"itemid":1,"itemname":"\u5730\u9762","bigitem":"\u53A8\u623F","unitprice":"20","unit":null,"size":"100","price":null,"content":null}],"total":1}
但是 alert(records[0].get('itemname'));为空 。始终没数据显示的,哪位哥有经验求教啊,谢谢了,分不多
...全文
235 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ma1986 2011-09-09
  • 打赏
  • 举报
回复
各位谢谢你们的帮助,上面的那个问题已经解决了 我用的是4.0,你们说的我都用过 ,后来参照文档,把reader放到了proxy里面
proxy : new Ext.data.HttpProxy({
url : 'detail_qurey.asp?projectid='+projectid, //说明后台的serverlet
method : 'POST',
reader : new Ext.data.JsonReader({
root : "rows",
totalProperty : 'total',
id: 'itemid'
},Task) //说明数据结构

}),
数据就出来了,不过新问题出来了,我的目的是把新增的记录批量保存到数据库,getNewRecords()是获取新增记录,代码如下
text: '保存记录',
handler : function(){
var inserted=store.getNewRecords() ; var updated=store.getUpdatedRecords() ;
var deleted=store.getRemovedRecords() ;
Ext.Ajax.request({
url: '11.asp',
method:'POST',
params: {
projectid: projectid,
inserted:inserted, updated:updated,
deleted:deleted
},
success: function(response, opts) {
alert(response.responseText)
},

可是发现inserted[0].get("itemname")有正确数据而inserted返回的是[object,Object],服务器端接受处理数据出错,我无法确认inserted是json字符串还是什么,我估计是inserted数据格式有问题导致后台出错,各位有知道的么,谢谢
光曰不日 2011-09-09
  • 打赏
  • 举报
回复
都已经”inserted[0]“了,inserted当然是数组咯!返回当然是[object,Object]
光曰不日 2011-09-07
  • 打赏
  • 举报
回复
首先确定返回的数据类型,如果是字符串则可用alert(records.responseText)看到内容,如果已经是json了则按照对象的方法操作即可,根据你的json对象,itemname的读取应该这样:records.rows[0].itemname
SnowDrift 2011-09-07
  • 打赏
  • 举报
回复

if (success) {
if(store.getCount() != 0){
var sitemid = store.getAt(0).get('itemid');
var sitemname = store.getAt(0).get('itemname');
var sbigitem = store.getAt(0).get('bigitem');
...
}
}

LZ换成这个试试...
SnowDrift 2011-09-07
  • 打赏
  • 举报
回复
scope:this,
试试..
ma1986 2011-09-07
  • 打赏
  • 举报
回复
数据结构Task是这样定义的
Ext.define('Task', {
extend: 'Ext.data.Model',
idProperty: 'itemid',
fields: [
{name: 'itemid', type: 'int'},
{name: 'itemname', type: 'string'},
{name: 'bigitem', type: 'string'},
{name: 'unitprice', type: 'float'},
{name: 'unit', type: 'string'},
{name: 'size', type: 'float'},
{name: 'price', type: 'float'},
{name: 'content', type: 'string'}

]
});
ma1986 2011-09-07
  • 打赏
  • 举报
回复
自己顶哈

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧