Ext.plugins.ListPagingPlugin "pullrefresh" sencha touch - PullRequest
2 голосов
/ 18 ноября 2011

Я пытаюсь добавить слушателя к следующему, но он не будет срабатывать

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');
                     }
                }
            }],

То, что я хочу сделать, это когда кто-то тянет список, когда запускается событие обновления, мы получаем широту и долготу пользователей и загружаем значения в хранилище. Моя проблема заключается в сохранении beforeload: событие не генерирует должным образом пузырек событий, поэтому он запускает сохранение вызова 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.

Я действительно просмотрел все форумы, документацию, но мне просто нужно какое-то руководство по настройке слушателя и всплывающих событий, я думаю. Спасибо тебе.

Ответы [ 2 ]

5 голосов
/ 03 декабря 2011

Вот как вы это делаете: 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 нет множества рабочих примеров, поэтому я буду публиковать ответы на свои вопросы по мере их нахождения.

0 голосов
/ 21 апреля 2013

Я немного обновил это для работы с Sencha 2.1 и мои потребности

Мне нужно было установить несколько дополнительных параметров при запуске pullRefresh (в моем случае для отображения разных фильтров одного и того же канала). Приведенный выше пример помог, но мне пришлось внести некоторые изменения - это работает для меня на 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);
    });
  }
}]
...