EXTJS过滤有一个关联

EXTJS过滤有一个关联,extjs,extjs4,Extjs,Extjs4,我有一个带有自定义渲染器的网格,请参见下文 { text: 'Last Name', dataIndex:'LastName', renderer: function(v, m, r) { return r.getDemographic().get('LastName'); }

我有一个带有自定义渲染器的网格,请参见下文

{                 text: 'Last Name',
                    dataIndex:'LastName',
                    renderer: function(v, m, r) {
                        return r.getDemographic().get('LastName');
                    }           
                }
我希望能够在用户键入时过滤掉属性,我有以下几点

{
                    fieldLabel: 'Last Name',
                    emptyText: 'Last Name',
                    listeners: {
                        change: function (field, newValue, oldValue, options) {

                            var grid = Ext.getCmp('Grid');
                            grid.store.clearFilter();


                            grid.store.filter([
                                { property: "Demographic.LastName", value: newValue }
                            ]);
                        }
                    }



                }
Ext.define('Test', {
    extend: 'Ext.data.Model',

    fields: [
       'id'
    ],


        { type: 'hasOne', model: 'Demographic', associationKey: 'Demographic', getterName: 'getDemographic' }]

});
问题是,该属性不是它的本来面目,我无法找到需要绑定到的属性的调用对象。模型如下所示

{
                    fieldLabel: 'Last Name',
                    emptyText: 'Last Name',
                    listeners: {
                        change: function (field, newValue, oldValue, options) {

                            var grid = Ext.getCmp('Grid');
                            grid.store.clearFilter();


                            grid.store.filter([
                                { property: "Demographic.LastName", value: newValue }
                            ]);
                        }
                    }



                }
Ext.define('Test', {
    extend: 'Ext.data.Model',

    fields: [
       'id'
    ],


        { type: 'hasOne', model: 'Demographic', associationKey: 'Demographic', getterName: 'getDemographic' }]

});

由于它是一个hasOne关联,您可以尝试向您的测试模型添加一个额外的字段,该字段映射到Demographic.LastName,您可以使用该字段直接在测试模型上进行筛选

Ext.define('Test', {
    extend: 'Ext.data.Model',

    fields: [
       'id',
       {name: 'MappedLastName', mapping: 'Demographic.LastName'}
    ],

    { type: 'hasOne', model: 'Demographic', associationKey: 'Demographic', getterName: 'getDemographic' }]

});
然后您可以使用它进行过滤

grid.store.filter([
      { property: "MappedLastName", value: newValue }
]);

使用具有以下功能的筛选器方法:

grid.store.clearFilter(true);
grid.store.filter({ filterFn: function(item) { 
     return item.getDemographic().get('LastName') == newValue; 
    }
});

这不起作用。item.getDemographic().get('LastName')返回NULL,因为我认为它需要进入回调