2013-05-22 52 views
0

編輯有效載荷要求我有過濾器:如何使用ExtJS的

store.filter([Ext.create('Ext.util.Filter', { 
         property : "firstName", 
         value : Ext.getCmp("firstName").getValue(), 
         root : 'data' 
        }), Ext.create('Ext.util.Filter', { 
         property : "lastName", 
         value : Ext.getCmp("lastName").getValue(), 
         root : 'data' 
        }), Ext.create('Ext.util.Filter', { 
         property : "gender", 
         value : "MALE",//Ext.getCmp("gender").getValue(), 
         root : 'data' 
        }), Ext.create('Ext.util.Filter', { 
         property : "ssn", 
         value : Ext.getCmp("ssn").getValue(), 
         root : 'data' 
        }), Ext.create('Ext.util.Filter', { 
         property : "dateOfBirth", 
         value : Ext.getCmp('dateOfBirthTo').getValue(), 
         root : 'data', 
         operator : "<" 
        })]); 

其中創建該有效載荷:

{..."filter":[{"property":"firstName","value":""},{"property":"lastName","value":""},{"property":"gender","value":"MALE"},{"property":"ssn","value":""},{"property":"dateOfBirth","value":"2013-05-22T00:00:00"}]}],...} 

如何我可以改變這種負載?我正在使用extdirectspring,它需要一些額外的參數來創建正確的過濾器。取而代之的{"property":"dateOfBirth","value":"2013-05-22T00:00:00"}

我需要:

{"property":"dateOfBirth","value":"2013-05-22T00:00:00", "type":"date","operator":"lte"}

回答

1

還沒有嘗試過,但只是在源代碼快速一眼,看來,你可以覆蓋encodeFilters()的方法Ext.data.proxy.Server。下面是它目前的樣子:

encodeFilters: function(filters) { 
    var min = [], 
     length = filters.length, 
     i = 0; 

    for (; i < length; i++) { 
     min[i] = { 
      property: filters[i].property, 
      value : filters[i].value, 
      // add your custom params here 
     }; 
    } 
    return this.applyEncoding(min); 
} 

換句話說,當你創建你的過濾器,我相信你可以在自定義配置添加到這些,再與覆蓋確保它們包含(如果存在的話)時,該請求被提出。

+0

thx很多年它的工作。 – hudi