3

在标准的“Pull to Refresh”插件中,列表存储得到更新。但是,我有两个列表,我需要为我的详细列表更新不同的商店。如何覆盖更新事件并重新加载我的其他商店?我尝试添加一个简单的侦听器,但它没有触发。

[更新]

我从Sencha 网站得到了这个片段来工作:

插件:[
          {
             xclass: 'Ext.plugin.PullRefresh',
              pullRefreshText: '下拉查看更多新事件!',
              refreshFn:函数(插件){
                  console.log("我被拉");
              }
           }
          ]

原始代码:

Ext.define('SenchaFiddle.view.ListView', {
    扩展:'Ext.dataview.List',
    xtype: '主列表',

    配置:{
        插件:[
            '拉刷新',
            {
                pullRefreshText: '去做吧!',
                类型:'列表分页',
                // 不要提供“加载更多”消息
                自动分页:假,

                刷新Fn:函数(){             
                  console.log("繁荣");
                },

                听众:{
                    'updatedata':函数(插件,列表){
                        console.log("获取数据");
                    }
                }

            }
        ],
        布局:'适合',
        宽度:300,
        itemTpl: '{文本}'

    }
});
4

3 回答 3

6

在 Sencha Touch 2.2 中,他们refreshFn从 Ext.util.PullRefresh 中删除了配置。通过覆盖Ext.util.PullRefresh 中的函数,我已经成功地refreshFn使用新版本的 Sencha Touch实现了自定义......fetchLatest

Ext.define('MyApp.overrides.PullRefreshOverride', {
    override: 'Ext.plugin.PullRefresh',

    fetchLatest: function() {
        var list = this.getList();

        switch(list.getItemId()) {
            case "list1": 
                this.updateStore1();
                break;

            case "list2": 
                this.updateStore2();
                break;
        }

        this.callParent(arguments);
    },

    //My own custom function to add to the plugin
    updateStore1: function() {
        //Code to update store 1
    },

    //My own custom function to add to the plugin
    updateStore2: function {
        //Code to update store 2
    }
});
于 2013-06-03T16:37:07.133 回答
2

查看sencha-touch-all-debugExt.plugin.PullRefresh中的定义,我看到了这个配置:

    /*
     * @cfg {Function} refreshFn The function that will be called to refresh the list.
     * If this is not defined, the store's load function will be called.
     * The refresh function gets called with a reference to this plugin instance.
     * @accessor
     */
    refreshFn: null,

您可以通过refreshFnconfig.xml 实现所需的功能,这可能是一个好主意。

于 2012-05-19T02:52:26.737 回答
1

对于那些需要refreshFn靠背的人,有一个PullRefreshFn扩展PullRefresh

我需要 PullRefresh 由 Panel 而不是 List 或 Dataview 触发,并且我还需要在用户触发 PullRefresh 时手动加载数据并将数据设置到我的 Dataview。

为此,我需要refreshFnSencha 2.2 之前存在的配置功能,所以这是我的实现。


PullRefreshFn(修改)

Ext.define('Ext.plugin.PullRefreshFn', {
    extend: 'Ext.plugin.PullRefresh',
    alias: 'plugin.pullrefreshfn',
    requires: ['Ext.DateExtras'],

    config: {
        /**
         * @cfg {Function} refreshFn The function that will be called to refresh the list.
         * If this is not defined, the store's load function will be called.
         */
        refreshFn: null
    },

    fetchLatest: function() {
        if (this.getRefreshFn()) {
            this.getRefreshFn().call();
        } else {
            var store = this.getList().getStore(),
                proxy = store.getProxy(),
                operation;

            operation = Ext.create('Ext.data.Operation', {
                page: 1,
                start: 0,
                model: store.getModel(),
                limit: store.getPageSize(),
                action: 'read',
                sorters: store.getSorters(),
                filters: store.getRemoteFilter() ? store.getFilters() : []
            });

            proxy.read(operation, this.onLatestFetched, this);
        }
    }

});

我的控制器

Ext.define('myApp.controller.MyController', {
    extend: 'Ext.app.Controller',
    requires: ['Ext.plugin.PullRefreshFn'],

    ...

    // More code

    ...

    // Binds the Pull Refresh to myPanel view item.
    // myPanel is a panel. Not list nor dataview.
    setPullRefresh: function () {
        var me = this;

        // We get reference to myPanel and
        // we set PullRefreshFn
        this.getMyPanel().setPlugins([{
            xclass: 'Ext.plugin.PullRefreshFn',
            docked: 'top',

            // We set autoSnapBack to false,
            // as we are going to trigger this manually
            autoSnapBack: false,

            // refreshFn will be called upon user releasing for refresh.
            refreshFn: function() {

                // This is a custom function that sets data to our dataview list.
                // When it's done setting data, we trigger the snapBack.
                me.populateMylist(function () {
                    me.getMyPanel().getPlugins()[0].snapBack(true);
                });
            }
        }]);
    }

});
于 2014-10-03T05:44:08.377 回答