3

我有一个带有搜索(过滤)字段的表单,如下所示:

xtype: 'form',
id: 'searchPanel',
title: 'Search',
collapsible: true,
bodyPadding: 10,

height: 210,
buttonAlign: 'left',
defaults: {
    width: 400,
    labelWidth: 120,
    allowBlank: true,
    enableKeyEvents: true        
},
layout: {
    type: 'table',
    columns: 2
},
items: [
    {
        xtype: 'textfield',
        name: 'txtFltrSiteName',
        fieldLabel: 'Site name or alias',
        id: 'txtFltrSiteName'
    },


    {
        xtype: 'textfield',
        name: 'txtMonthTraffic',
        fieldLabel: 'Month traffic',
        id: 'txtMonthTraffic',
        style: 'margin-left: 100px;'
    },

    {
        xtype: 'combo',
        id: 'ddlFltrPM',
        name: 'ddlFltrPM',
        fieldLabel: 'Project manager',
        displayField: 'display_name',
        valueField: 'user_id',
        editable: false,
        store: new storeOfUsers({ filters: [{ property: 'user_group_code', value: 'projectmanager', exactMatch: true }] })
    },

    // and many other fields below


但是当我点击search按钮时,我有两个帖子请求。一 - 里面有过滤器,二是没有。

我的send按钮操作代码:


xtype: 'button',
id: 'btn_srch_set',
text: 'Searh',
margin: '10 7 0 0',
width: '',
handler: function() {       
    var filters = new Array();

    var site_name = Ext.getCmp('txtFltrSiteName').getValue();
    if(site_name.length > 0)
        filters.push({dataIndex: 'site_name', type: 'string', value: site_name}); 

    var project_name = Ext.getCmp('txtFltrProjectName').getValue();
    if(project_name.length > 0)
        filters.push({dataIndex: 'project_name', type: 'string', value: project_name});

    var pm = Ext.getCmp('ddlFltrPM').getValue();
    if(pm && pm > 0)    
        filters.push({dataIndex: 'project_manager_id', type: 'int', value: {'eq':pm}});

    // many other fields

    listOfSites.filters.removeAll();
    if(filters.length > 0)  
        listOfSites.filters.addFilters(filters);
    listOfSites.store.load(); 
}



PS当我在按钮处理函数
中覆盖这一行时:search

filters.push({dataIndex: 'project_manager_id', type: 'string', value: pm});

一切都很好,只有一个请求,所以问题可能就在这里。但我被卡住了,不知道为什么它会这样工作。


感谢您的帮助,
斯坦尼斯拉夫。

UPD*

        var filters = {
        ftype: 'filters',
        // encode and local configuration options defined previously for easier reuse
        encode: true, // json encode the filter query
        local: false,
        filters: [{
            type: 'string',
            dataIndex: 'site_name'
        }, {
            type: 'date',
            dataIndex: 'startdate'
        }, {
            type: 'string',
            dataIndex: 'project_name'

        // more fields below
4

1 回答 1

5

尝试关注

if(filters.length > 0)  
    listOfSites.filters.addFilters(filters);
else
    listOfSites.store.load();

addFilters()可能已经打电话sync()

于 2012-11-23T12:59:19.580 回答