2007-12-18

Ext Grid

关键字: Ext Grid
Ext在和后端通信使用Json时,要使用"callback('Json');"这种形式,原因是
引用
grid提交分页数据的时候后面还会自动跟随一个可以说是标识的字段callback=stcCallback1001
每提交一次请求,callback就会自增,也就是说第二次就是callback=stcCallback1002
对应的,你的php文件回传json数据的时候也要带上这个值,来确定是哪次的请求所返回的结果
格式是:
stcCallback1001(
{ ‘results’: 2, ‘rows’: [
{ ‘id’: 1, ‘name’: ‘Bill’, occupation: ‘Gardener’ },
{ ‘id’: 2, ‘name’: ‘Ben’, occupation: ‘Horticulturalist’ } ]
}
);

他每次提交的数据是附加在网址后面的格式是
?start=0&limit=25&_dc=1185695314632&callback=stcCallback1001
statr:起始数据值
limit:每页数据条数
_dc:自动生成的时间戳
callback:回传的确认值

要注意的是JSON-CODE中要严格按照其格式定义:{"totalProperty:".总行数,“ROOT:".JSON_ENCODE($DATA)}
另外,在ext-js中,使用JsonReader声明所读的数据是日期时,也要注意,要不就不要声明,要声明就得确定jsondata中的日期格式与你声明的一致。

出自:http://www.centuryidea.cn/index.php?tag=php

所以对应的服务器端的实现:
String callback=request.getParameter("callback");
String json = callback+"({totalProperty:100,root:[";
json += "{col1:" + 1 + ",col2:'name" + i + "',col3:'descn" + 1 + "'}";
json += "]});";

回传的结果类似于:
stcCallback1001({totalProperty:100,root:[{col1:1,col2:'name1',col3:'descn1'}]});


在创建Ext.data.Store对象时,proxy属性使用Ext.data.ScriptTagProxy,不要使用Ext.data.HttpProxy。
引用

Ext API
Class Ext.data.HttpProxy
Note that this class cannot be used to retrieve data from a domain other than the domain from which the running page was served.


Class Ext.data.ScriptTagProxy
Note that if you are retrieving data from a page that is in a domain that is NOT the same as the originating domain of the running page, you must use this class, rather than HttpProxy.



很奇怪,使用这种形式proxy: new Ext.data.ScriptTagProxy({url:'PagingGrid.jsp'})可以正常显示,但proxy: new Ext.data.HttpProxy({url:'PagingGrid.jsp'})这种就不行(我理解错了?)。
  • testExt.rar (2.4 MB)
  • 描述: 我使用tomcat,解压后直接放到webapps下使用
  • 下载次数: 328
评论
zhangtianqi 2008-04-08
本地两个都可以用的
zhangtianqi 2008-04-08
这个是跨域执行的,服务器和执行文件不再一起放着的,所以用ScriptTagProxy撒
yangfengjob 2008-04-07
感谢楼主..这虽然是个小问题.
但是困扰了几天..
(感激中....)
发表评论

提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则

您还没有登录,请登录后发表评论

bill.end
搜索本博客
博客分类
最近加入圈子
存档
最新评论
  • Ext Grid
    本地两个都可以用的
    -- by zhangtianqi
  • Ext Grid
    这个是跨域执行的,服务器和执行文件不再一起放着的,所以用ScriptTagPro ...
    -- by zhangtianqi
  • Ext Grid
    感谢楼主..这虽然是个小问题. 但是困扰了几天.. (感激中....)
    -- by yangfengjob