码迷,mamicode.com
首页 > Web开发 > 详细

Ext Store Proxy Ajax

时间:2015-05-26 13:59:20      阅读:353      评论:0      收藏:0      [点我收藏+]

标签:

使用Store ajax的方式来获取数据

    Ext.onReady(function() {
        var store = new Ext.data.JsonStore({
            // store configs
            storeId: ‘myStore‘,
            autoLoad: true,
            proxy: {
                type: ‘ajax‘,
                url: ‘getImage.php‘,
                reader: {
                    type: ‘json‘,
                    root: ‘images‘,
                    idProperty: ‘name‘,
                    //getData的函数最先触发
                    //这里配置过getData就相当于把数据取走了
                    //后面on事件  函数就不能通过records取到数据了 还是可以通过store.getProxy().getReader().rawData去到数据
                    // afterRequest 则根本取不到数据
                    // getData: function(data){
                    //     console.log(‘getData in reader‘);
                    //     console.log(data);
                    // }
                },
                afterRequest: function(req, res) {
                    console.log("After Request!", req.operation.response);
                }
            },

            //alternatively, a Ext.data.Model name can be given (see Ext.data.Store for an example)
            fields: [‘name‘, ‘url‘, {
                name: ‘size‘,
                type: ‘float‘
            }, {
                name: ‘lastmod‘,
                type: ‘date‘
            }]
        });
        store.load();
        //会调用多次..
        store.on({
            ‘load‘: function(store, records, success, opts) {
                console.log(‘on1‘);
                console.log(success);
                //records 是 []
                console.log(records);
                //PS rawData是一个{}
                console.log(store.getProxy().getReader().rawData);
            }
        }, this, {single:true});
        store.on(‘load‘, function(store, records, success, eOpts ){
            console.log(‘on2‘);
            console.log(success);
            console.log(records);
            console.log(store.getProxy().getReader().rawData);
        });
        store.load({
            callback: function(records, opts, success) {
                console.log(‘load‘);
                console.log(success);
                console.log(records);
            }
        });
        // console.log(store);
    });

 

Ext Store Proxy Ajax

标签:

原文地址:http://www.cnblogs.com/cart55free99/p/4530275.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!