搜索值时不会加载包含搜索数据的视图[Shopware 5]

2ledvvac  于 2022-11-04  发布在  PWA
关注(0)|答案(1)|浏览(227)

我已经创建了一个后端窗口,并添加了搜索功能。
每当我搜索任何值时,比如说5004。ExtJS中change事件上的console.log(store.data.items)首先显示所有结果

之后,如果我搜索任何其他值,如5007。则在console.log(store.data.items)中,它将在控制台选项卡中显示5004的先前结果

网络选项卡显示PHP端带来了正确的结果,但在ExtJ上,我无法在网格中反映搜索的数据。
这是我的代码结构

资源/视图/后端/我的测试模块/app.js

Ext.define('Shopware.apps.MyTestModule', {
    extend: 'Enlight.app.SubApplication',

    name:'Shopware.apps.MyTestModule',

    loadPath: '{url action=load}',
    bulkLoad: true,

    controllers: [
        'Main',
        'Filter'
    ],

    views: [
        'list.Window',
        'list.List'
    ],

    models: [ 'MyTestModule' ],
    stores: [ 'MyTestModule' ],

    launch: function() {
        return this.getController('Main').mainWindow;
    }
});

资源/视图/后端/测试模块/控制器/过滤器.js

Ext.define('Shopware.apps.MyTestModule.controller.Filter', {

    extend:'Ext.app.Controller',

    init:function () {
        var me = this;

        me.control({
            'my-test-module-listing-grid textfield[action=searchTicket]': {
                searchTicket: me.onSearchTicket
            }
        });
        me.callParent(arguments);
    },

    onSearchTicket: function (value) {
        var me = this,
            store = me.getStore('MyTestModule');

        var searchString = Ext.String.trim(value);

        // scroll the store to first page
        store.currentPage = 1;

        // If the search-value is empty, reset the filter
        if (searchString.length === 0) {
            store.clearFilter();
        } else {
            // This won't reload the store
            store.filters.clear();
            // Loads the store with a special filter
            store.filter('searchValue', searchString);

        }

        console.log(store.data.items);  
    }
});

资源/视图/后端/测试模块/模型/测试模块.js

Ext.define('Shopware.apps.MyTestModule.model.MyTestModule', {
    extend: 'Ext.data.Model',

    fields: [
        { name : 'id', type: 'int' },
        { name : 'some_field_one', type: 'string' },
        { name : 'order_number', type: 'string' },
        { name : 'ticket_number', type: 'string' },
        { name : 'some_field_two', type: 'string' },
        { name : 'some_field_three', type: 'string' }
    ],

    /**
     * Configure the data communication
     * @object
     */
    proxy: {
        type: 'ajax',

        /**
         * Configure the url mapping for the different
         * store operations based on
         * @object
         */
        api: {
            read: '{url controller="MyTestModule" action="list"}',
            update: '{url controller="MyTestModule" action="update"}',
        },

        /**
         * Configure the data reader
         * @object
         */
        reader: {
            type: 'json',
            root: 'data',
            totalProperty: 'total'
        }
    }
});

资源/视图/后端/我的测试模块/存储/我的测试模块.js

Ext.define('Shopware.apps.MyTestModule.store.MyTestModule', {
    extend: 'Ext.data.Store',

    pageSize: 10,
    remoteFilter: true,
    remoteSort: true,

    autoLoad: true,

    /**
     * Define the used model for this store
     * @string
     */
    model: 'Shopware.apps.MyTestModule.model.MyTestModule'
});

有线索吗?

jqjz2hbq

jqjz2hbq1#

这种方法经过一点修改后对我上面的案例很有效。
How to refresh or reload panel view in extjs4.1
我所做的就是在我的Resources/views/backend/my_test_module/controller/filter.js中在onSearchTicket()
我添加了这一行

Ext.ComponentQuery.query('my-test-module-listing-grid')[0].store.filter('searchValue', searchString);

所以现在看起来像这样

onSearchTicket: function (value) {
        var me = this,
            store = me.getStore('MyTestModule');

        var searchString = Ext.String.trim(value);

        // scroll the store to first page
        store.currentPage = 1;

        // If the search-value is empty, reset the filter
        if (searchString.length === 0) {
            Ext.ComponentQuery.query('my-test-module-listing-grid')[0].store.clearFilter();
        } else {
            // otherwise filter the store with filtered value
            Ext.ComponentQuery.query('my-test-module-listing-grid')[0].store.filter('searchValue', searchString);
        }
    }

Ext.ComponentQuery.query()的解释可以在这个答案中找到
https://stackoverflow.com/a/35193444/7473771

相关问题