首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Extjs 项目中常用的小技巧,也许你用得着(5)--设置 Ext.data.Store 传参的请求方式

Extjs 项目中常用的小技巧,也许你用得着(5)--设置 Ext.data.Store 传参的请求方式

作者头像
hbbliyong
发布2018-03-05 16:28:27
1.5K0
发布2018-03-05 16:28:27
举报
文章被收录于专栏:hbbliyonghbbliyong

1.extjs 给怎么给panel设背景色

设置bodyStyle:'background:#ffc;padding:10px;',

var resultsPanel = Ext.create('Ext.panel.Panel', {
    title: 'Results',
    width: 600,
    height: 400,
    renderTo: Ext.getBody(),
    bodyStyle: 'background:#ffc; padding:10px;',
    layout: {
        type: 'vbox',       // Arrange child items vertically
        align: 'stretch',    // Each takes up full width
        padding: 5
    },
    items: [{               // Results grid specified as a config object with an xtype of 'grid'
        xtype: 'grid',
        columns: [{header: 'Column One'}],            // One header just for show. There's no data,
        store: Ext.create('Ext.data.ArrayStore', {}), // A dummy empty data store
        flex: 1                                       // Use 1/3 of Container's height (hint to Box layout)
    }, {
        xtype: 'splitter'   // A splitter between the two child items
    }, {                    // Details Panel specified as a config object (no xtype defaults to 'panel').
        title: 'Details',
        bodyPadding: 10,
        items: [{
            fieldLabel: 'Data item',
            xtype: 'textfield'
        }], // An array of form fields
        flex: 2             // Use 2/3 of Container's height (hint to Box layout)
    }]
});

2. Extjs4.0 设置 Ext.data.Store 传参的请求方式

var Store = Ext.create('Ext.data.Store', {  
    pageSize: pageSize,  
    model: 'Ext.data.Model名称',  
    autoLoad: false,  
    proxy: {  
        type: 'ajax',  
        url: '请求路径',  
        getMethod: function(){ return 'POST'; },//亮点,设置请求方式,默认为GET  
        reader: {  
            type: 'json',  
            root: 'Data',  
            totalProperty: 'totalCount'  
        }  
    },   
    listeners: {  
        'beforeload': function (store, op, options) {  
            var params = {  
                //参数  
            };  
            Ext.apply(store.proxy.extraParams, params);   
        }  
    }  
});  

3.ExtJS grid 带参数查询分页 store 传额外参数解决办法

在store的beforeload事件里面重写store.proxy.extraParams,添加新参数

就不必每次都手动的添加参数

store.on('beforeload', function (store, options) {
        var new_params = { name: Ext.getCmp('search').getValue() };
        Ext.apply(store.proxy.extraParams, new_params);
        // alert('beforeload');
    });
在Extjs3 中的
store.on('beforeload', function () {
            store.baseParams = {
                name: '5555555',
                intss: '666666666'
            };
        }); 

下面给出完整的代码。原理很简单,将搜索条件放在store的baseParams中,每次加载都赋值。

只是需要强制赋值,因为默认的pagetoolbar只会把start、limit、page、sort、dir传递给store。

var store = new Ext.data.Store({  
       pageSize: GridPageSize,  
       model: 'Master',  
       autoLoad: false,   
       proxy: {  
           type: 'ajax',  
           url: '/master/GetMasterData',  
           reader: {  
               type: 'json',  
               root: 'data',  
               totalProperty: 'totalCount'  
           }  
       },  
       fields: [  
           { name: 'Id' },  
           { name: 'Master_Name' }  
           
       //排序  
       sorters: [{  
           property: 'Master_Name',  
           direction: 'DESC'  
       }]   
        
   });  
store.on('beforeload', function (store, options) {  
        var new_params = { name: Ext.getCmp('search').getValue() };  
        Ext.apply(store.proxy.extraParams, new_params);  
        // alert('beforeload');  
    });  
store.load({  
       params: { start: 0, limit: GridPageSize }  
   })  
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2013-08-13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档