【问题标题】:Read data from server with Sencha touch使用 Sencha touch 从服务器读取数据
【发布时间】:2014-11-22 22:18:56
【问题描述】:

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

test.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)

{"data":[{"manufacture":"SSANYONG","model":"ACTYON","price":100000},{"manufacture":"SUZUKI","model":"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);
}

汽车等级是

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

当我运行 aspx 时,在 localhost 中显示与 car.json 相同的文本,我尝试使用不同的代码

将“应用程序/json”更改为“应用程序/x-json”, “应用程序/json”到“文本/javascript”, “代理类型:ajax”到“scripttag”, “代理类型:ajax”到“休息”

不工作。

【问题讨论】:

    标签: c# asp.net json sencha-touch


    【解决方案1】:

    示例终于可以了!,只需要在服务器上容纳APPLICATION aspx(不是localhost和主管部门课程),还要在服务器上托管sencha touch的应用程序,以便一切正常

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-13
      相关资源
      最近更新 更多