【问题标题】:Sencha Touch 2 - storing values from json using proxy not working for meSencha Touch 2 - 使用代理从 json 存储值不适合我
【发布时间】:2012-04-27 11:47:11
【问题描述】:

我是 Sencha Touch 2 的新手,我正在尝试使用 store 和模型通过代理从 json 中存储值,但不要在哪里我错了

我的模型

Ext.regModel('Product', {
    fields: [
        {name: 'name',        type: 'string'},
        {name: 'description', type: 'string'},
        {name: 'price',       type: 'float'},
        {name: 'image_url',   type: 'string'},
        {name: 'in_stock',    type: 'boolean'}
    ]

});

我的商店

Dzineapp.BlogStore = new Ext.data.Store({
model: 'Product',
autoLoad: false,
proxy: new Ext.data.AjaxProxy({
    type: 'ajax',
    url: 'http://localhost/products.json',
    reader: {
        type: 'json',
        root: 'products'
    },
    writer: {
        encode: true,
        type: 'json'
    }
    })
});

Products.json

{
    "products": [
        {"name": "Some Product",    "price": 9.99, "image_url": "product1.jpg", "in_stock": true},
        {"name": "Another Product", "price": 7.50, "image_url": "product2.jpg", "in_stock": true},
        {"name": "A third product", "price": 2.35, "image_url": "product3.jpg", "in_stock": false}

    ]
}

我的观点

 Dzineapp.blogPanel = new Ext.List({
            id: 'bloglist',
            store: Dzineapp.BlogStore,
            itemTpl: '<div class="contact">{name}</div>'
        });

但是我的应用程序没有显示任何值,任何人都可以在我犯错误的地方帮助我.. 我只是 sencha 的初学者

【问题讨论】:

    标签: ajax model proxy extjs store


    【解决方案1】:

    你能更新你的商店如下

    Dzineapp.BlogStore = new Ext.data.Store({
       model: 'Product',
       autoLoad: true,
       proxy: {
         type: 'ajax',
         url: 'http://localhost/products.json',
         reader: {
           type: 'json',
           root: 'products'
         }
       }
    });
    

    我希望它有效。

    我们必须加载商店来显示数据。

    谢谢, 斯瓦蒂。

    【讨论】:

      【解决方案2】:

      1) 您应该使用 Ext.create() 而不是 new ...(但这应该可以正常工作)

      2) 您应该在列表配置中的 store 值周围添加 '

      3) 检查您是否将您的商店添加到您的 app.js 中的 stores[] 或在您的列表中添加一个 require。

      4) 使用 firebug/chrome 开发工具检查您的请求是否正常 (HTTP : 200) 以及您是否获得了 json。

      希望对你有帮助

      【讨论】:

        【解决方案3】:

        在您的商店配置中而不是使用

        root: 'products'
        

        尝试使用

        rootProperty: 'products'
        

        【讨论】:

          猜你喜欢
          • 2012-05-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-05-23
          • 1970-01-01
          • 2012-06-12
          • 2012-07-24
          • 2012-09-13
          相关资源
          最近更新 更多