简体   繁体   English

如何在缓冲存储区中设置数据

[英]How to set data in Buffered Store

I am using ExtJS buffered store for paging and other purpose. 我正在使用ExtJS缓冲存储进行分页和其他用途。 I want to load data in buffered store. 我想在缓冲存储中加载数据。 in normal store I can use 我可以在普通商店里使用

store.loadData(thistore.data.items);

But in buffered store I can not use loadData . 但是在缓冲存储区中,我不能使用loadData I can see as per my code i am getting data in response but I don't know how to set the data. 我可以按照我的代码看到我正在获取数据作为响应,但是我不知道如何设置数据。 Can one help me what is the alternate of loadData in Ext.data.BufferedStore 可以帮我一下Ext.data.BufferedStoreloadData的替代方法是什么

Have you tried store.load method ? 您是否尝试过store.load方法

store.load({
        callback: function(records, operation, success) {
            console.log(records);
        }
    });

UPDATE 更新

Based on this sencha example, i created an example for you using extjs 6.5.2 classic. 基于这个 sencha示例,我使用extjs 6.5.2 classic为您创建了一个示例。 I used the classic toolkit because in modern virtualstore is being used instead of bufferedstore . 我之所以使用经典工具包,是因为在现代virtualstore它被使用来代替bufferedstore

Here is the code: 这是代码:

Ext.define('ForumThread', {
    extend: 'Ext.data.Model',
    fields: [{
        name: 'title',
        mapping: 'topic_title'
    }, {
        name: 'forumtitle',
        mapping: 'forum_title'
    }, {
        name: 'forumid',
        type: 'int'
    }, {
        name: 'username',
        mapping: 'author'
    }, {
            name: 'replycount', 
            mapping: 'reply_count',
            type: 'int'
    }, {
            name: 'lastpost', 
            mapping: 'post_time', 
            type: 'date', 
            dateFormat: 'timestamp'
    },
        'lastposter', 'excerpt', 'topic_id'
    ],
    idProperty: 'post_id'
});

var store = Ext.create('Ext.data.BufferedStore', {
    id: 'store',
    model: 'ForumThread',

    // The topics-remote.php script appears to be hardcoded to use 50, and ignores this parameter, so we
    // are forced to use 50 here instead of a possibly more efficient value.
    pageSize: 50,

    // This web service seems slow, so keep lots of data in the pipeline ahead!
    leadingBufferZone: 1000,
    proxy: {
        // load using script tags for cross domain, if the data in on the same domain as
        // this page, an HttpProxy would be better
        type: 'jsonp',
        url: 'https://www.sencha.com/forum/topics-remote.php',
        reader: {
            rootProperty: 'topics',
            totalProperty: 'totalCount'
        },
        // sends single sort as multi parameter
        simpleSortMode: true,

        // Parameter name to send filtering information in
        filterParam: 'query',
    },
    remoteFilter: true,
    autoLoad: false
});

function onSearchParamApplied () {
    var searchParam = grid.down('#txtSearchParam').getValue();

    var store = grid.getStore();
    if (!store)
        return;

    store.getProxy().extraParams['query'] = searchParam;

    store.reload({ 
        callback: function (records, operation, success) {
            grid.down('#status').setValue(store.getTotalCount());
        }
    });
}

function onStoreLoadClick () {
    var store = grid.getStore();
    if (!store)
        return;

    store.load({ 
        callback: function (records, operation, success) {
            grid.down('#status').setValue(store.getTotalCount());
        }
    });
}

var grid = Ext.create('Ext.grid.Panel', {
    width: 700,
    height: 470,
    padding: 10,
    collapsible: true,
    title: 'ExtJS.com - Browse Forums',
    store: store,
    loadMask: true,
    dockedItems: [{
        dock: 'top',
        xtype: 'toolbar',
        items: [{
            xtype: 'textfield',
            itemId: 'txtSearchParam',
            width: 400,
            fieldLabel: 'Search',
            labelWidth: 50,
        }, {
            xtype: 'button',
            iconCls: 'x-fa fa-search',
            tooltip: 'Reload buffered store with the new param',
            handler: onSearchParamApplied
        }, {
            xtype: 'button',
            text: 'loadGrid',
            handler: onStoreLoadClick
        },'->', {
            xtype: 'displayfield',
            itemId: 'status',
            fieldLabel: 'Count ',
            value: '0' //initial value
        }]
    }],
    selModel: {
        pruneRemoved: false
    },
    multiSelect: true,
    viewConfig: {
        trackOver: false,
        emptyText: '<h1 style="margin:20px">No matching results</h1>'
    },
    // grid columns
    columns:[{
        xtype: 'rownumberer',
        width: 50,
        sortable: false
    },{
        tdCls: 'x-grid-cell-topic',
        text: "Topic",
        dataIndex: 'title',
        flex: 1,
        //renderer: renderTopic,
        sortable: false
    },{
        text: "Author",
        dataIndex: 'username',
        width: 100,
        hidden: true,
        sortable: false
    },{
        text: "Replies",
        dataIndex: 'replycount',
        align: 'center',
        width: 70,
        sortable: false
    },{
        id: 'last',
        text: "Last Post",
        dataIndex: 'lastpost',
        width: 130,
        renderer: Ext.util.Format.dateRenderer('n/j/Y g:i A'),
        sortable: false
    }],
    renderTo: Ext.getBody()
});

Points of interest: 兴趣点:

-Click "loadGrid" button to load the records. -单击“ loadGrid” button以加载记录。

-Add some text to the "Search" textfield and click the search button in order to refresh the grid based on the query provide by the text you entered. -将一些文本添加到“搜索”文本textfield ,然后单击搜索按钮,以便根据您输入的文本提供的查询刷新网格。

You can also add the code inside a sencha fiddle (select a classic theme from the top right selectfield) and run it. 您也可以在sencha 小提琴中添加代码(从右上角选择字段中选择经典主题)并运行它。

I hope i helped. 希望我能帮上忙。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM