Ext学习系列(9)-- Ext.data.HttpProxy

httpProxy是从object继承来的,事实上source中它和下面的Ext.data.MemoryProxy/Ext.data.ScriptTagProxy都继承于DataProxy
HttpProxy用于远程代理,而且服务端返回信息时必须指定Content-Type属性为"text/xml".

HttpProxy( Object conn )
构造一个HttpProxy对象,参数可以是一个类似于{url: 'foo.php'}这样的json对象,也可以是一个Ext.data.Connection对象,如果参数没有指定,将使用Ext.Ajax对象将被用于发起请求

getConnection() : Connection
得到当前连接对象

load( Object params, Ext.data.DataReader reader, Function callback, Object scope, Object arg ) : void
从配置的connection对象得到record数据块,并激发callback
params:        发起http请求时所要传递到服务端的参数
DataReader:    见DataReader
callback:    回叫方法,第一个参数为接收到的信息,第二个参数为arg,第三个是成功标志
scope:        范围
arg:        这儿的参数将会传递给回叫函数callback

 

例:

JS代码:

    Ext.onReady(function() {
            //数据
        var proxy1 = new Ext.data.HttpProxy({ url: "ExtData/Ext_Info3.aspx" });
         
            var reader1 = new Ext.data.JsonReader({
                root: "data",
                id: "id",
                totalProperty: "totalCount",
                successProperty: "success"
            },
                          [
                           { name: "id", mapping: "id" },
                           { name: "name", mapping: "name" },
                           { name: "sex", mapping: "sex" }
                          ]
                            );

            var ds = new Ext.data.Store({
                proxy: proxy1,
                reader: reader1
            });
           ds.load();
           
           
            //获取数据方法
            Ext.get("button1").on("click", function() {

                for (var a = 0; a < ds.getCount(); a++) {
                    alert(ds.getAt(a).get("name"));
                }
                alert("完成");
            });

        });

 

HTML代码:

<%=Info %>

CS代码:

    public StringBuilder Info = new StringBuilder();
    protected void Page_Load(object sender, EventArgs e)
    {
        Info.Append("{totalCount:3,success:true,error:'',singleInfo:'',data:[");
        Info.Append("{'id':'1','name':'tianzhi','sex':'男'},");
        Info.Append("{'id':'2','name':'tianzhi1','sex':'男'},");
        Info.Append("{'id':'3','name':'tianzhi2','sex':'男'}");
        Info.Append("]}");
    }

posted @ 2011-08-10 14:04  杉木的征途  阅读(1010)  评论(0编辑  收藏  举报