【问题标题】:Ext.plugins.ListPagingPlugin "pullrefresh" sencha touchExt.plugins.ListPagingPlugin "pullrefresh" sencha touch
【发布时间】:2011-11-17 20:08:30
【问题描述】:

我正在尝试向以下内容添加一个侦听器,但它不会触发

plugins: [{
                ptype: 'pullrefresh',
                autoPaging: true,
                listeners: {
                     'released': function(plugin,list){
                       // call the plugins processComplete method to hide the 'loading' indicator
                      /* your_store.on('load', plugin.processComplete,     plugin, {single:true});
                       // do whatever needs to happen for reload
                       your_store.load();*/
                       alert('test');
                     }
                }
            }],

我想要做的是有人在触发刷新事件时拉出列表,我们获取用户纬度和经度并将值加载到商店中。我的问题是存储前加载:事件没有正确地事件气泡,因此在获取用户地理位置之前它会触发存储 json 调用。

My Store{

listeners: {
        beforeload: function(){

            console.log( 'me1' );
            //call this to write to location services on device
            if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(function(position) {
                    console.log( 'me2' );
                    Rad.stores.games.getProxy().extraParams.lat  = position.coords.latitude;
                    Rad.stores.games.getProxy().extraParams.long  = position.coords.longitude;  
                }); 
            }
            console.log( 'me3' );
        }
    }
}

如果您查看控制台,它会显示 me1,me3,me2.... 我希望它显示 me1,me2,me3。

我确实查看了所有论坛、文档,但我猜只需要一些关于设置侦听器和事件冒泡的指导。谢谢你。

【问题讨论】:

  • 很高兴您找到了答案,但您能否将其添加为答案(如下)而不是对您的问题进行编辑?等待一段时间后,您将被允许选择正确,这将结束您的问题。这有点奇怪,但我们就是这样做的。谢谢。

标签: sencha-touch extjs


【解决方案1】:

这是你的做法:refreshFn

        // pull refresh and listupdate plugins
        plugins: [
            {
                ptype: 'pullrefresh',
                refreshFn: function(callback, plugin) {
                    console.log( 'me1' );
                    if (navigator.geolocation) {
                        navigator.geolocation.getCurrentPosition(function(position) {
                            console.log( 'me2' );
                            Rad.stores.games.getProxy().extraParams.lat  = position.coords.latitude;
                            Rad.stores.games.getProxy().extraParams.long  = position.coords.longitude;  
                            var store = plugin.list.getStore();
                            store.load(function(records, operation, success) {
                                callback.call(plugin);
                                console.log( 'me3' );
                            });
                        }); 
                    }
                }
            },
            {
                ptype: 'listpaging',
                autoPaging: false,  
            }
        ],

这里是商店:

  Rad.stores.games = new Ext.data.Store({
id: 'games',
model: 'games',
autoLoad:false,
    clearOnPageLoad: false, 
proxy: {
   type: 'ajax',
   url : 'ajax/lc.php',
   reader: {
        type: 'json',
        root: 'results'
   }
},
extraParams:{
    format:'json'
}

});

我发现 sencha touch 没有很多工作示例,所以我会在找到问题后继续发布我自己的问题的答案。

【讨论】:

  • 该死的…… :) 特别是 Sencha Touch 2.0。很多东西需要适应..
  • 我已经放弃了煎茶 JQM 是要走的路,或者只是走原生路。
  • 我的评论是一年多以前的。我不想让人们气馁。在此期间发生了很多变化。我认为,对于大型/企业应用程序,JQM 缺乏 ST 可以提供的结构。我在 ST 和 JQM 方面都有经验,我必须使用像 knockoutJS 这样的框架和很多想象力才能完成一个体面的项目。但可以肯定的是,如果你想要一个小应用程序并且需要学习 ST,JQM 将可以工作。大多数开发人员已经了解 jQuery,因此学习曲线不会太陡峭。如果你能负担得起在每个主要平台上分别进行开发,原生总是最好的。但这一切有点离题:)
【解决方案2】:

我已经对此进行了一些更新,以适应 Sencha 2.1 和我的需求

当 pullRefresh 被触发时,我需要设置一些 extraParams(在我的例子中,用于显示同一提要的不同过滤器)。上面的例子有帮助,但我必须做一些调整——这在 Sencha Touch 2.1 上对我有用

我的商店称为“问题”,我需要从用户切换提要时设置的变量(MyApp.util.Config.currentFeed)设置“类型”参数。希望这可以帮助某人

plugins: [
{
  xclass: 'Ext.plugin.PullRefresh',
  pullRefreshText: 'Pull to refresh...',
  refreshFn: function() {
    console.log( 'firing pullrefresh event' );
    var store = Ext.getStore('Questions');
    store.getProxy().setExtraParam('type',MyApp.util.Config.currentFeed);
    Ext.Viewport.setMasked({
      xtype: 'loadmask'
    });
    store.load(function(records, operation, success) {
      console.log( 'finished pullrefresh event' );
      Ext.Viewport.setMasked(false);
    });
  }
}]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-27
    • 2012-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-15
    相关资源
    最近更新 更多