用Sencha触摸从服务器读取数据

本文关键字:读取 数据 服务器 Sencha 触摸 | 更新日期: 2023-09-27 18:12:47

我有一个sencha touch测试,代码如下

. js

Ext.setup({
   onReady: function() {        
        Ext.regModel('car', {
            fields: [                               
                {name: 'manufacture',type: 'string'},
                {name: 'model',   type: 'string'},
                {name: 'price',    type: 'decimal'}
            ]
        });
        var productsList = new Ext.DataView({
            store: new Ext.data.Store({
                model: 'car',
                proxy: {
                    type: 'ajax',
                    url : 'cars.json',
                    reader: {
                        type: 'json',
                        root: 'data'
                    }
                },
                autoLoad : true
            }),
            tpl: new Ext.XTemplate(
                '<tpl for=".">',
                    '<div class="item">',
                        '"{manufacture}"',
                        '"{model}"',
                        '"{price}"',
                    '</div>',
                '</tpl>'
            ),
            itemSelector: "div.item",
            fullscreen: true
        });
   }
});

json代码是(cars.json)

{"数据":[{"制造":"双龙"、"模型":"爱腾","价格":100000},{"制造":"铃木"、"模型":"ALTO"、"价格":80000}],"结果":3}

这个例子工作,但我已经从服务器读取数据,从c#/aspx的代码如下

protected void Page_Load(object sender, EventArgs e)
{
    List<car> oList = new List<car>();
    car c = new car();
    c.manufacture = "SSANYONG";
    c.model = "ACTYON";
    c.price = 100000;
    car d = new car();
    d.manufacture = "SUZUKI";
    d.model = "ALTO";
    d.price = 80000;
    oList.Add(c);
    oList.Add(d);
    string sJSON;
    System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
    sJSON = oSerializer.Serialize(oList);
    sJSON=string.Concat("{'"data'":", sJSON);
    sJSON=string.Concat(sJSON,",'"results'":3}");
    Response.ContentType = "application/json";
    Response.Write(sJSON);
}

car类是

public class car
{
    public string manufacture { get; set; }
    public string model { get; set; }
    public double price { get; set; }
}

当我运行aspx时,在localhost中显示了相同的文本。Json,我尝试用不同的代码

将"application/json"改为"application/x-json"application/json"到"text/javascript","代理类型:ajax"到"scripttag","代理类型:ajax"到"rest"

不工作。

用Sencha触摸从服务器读取数据

示例终于工作了!,只需在服务器上容纳应用程序aspx(不是本地主机和主管部门课程),还可以在服务器上托管sencha touch应用程序,以便一切工作