在Sencha Touch中是否有任何viewWillAppear like-function

时间:2013-04-01 12:57:40

标签: javascript extjs sencha-touch

每次视图显示时,我都会尝试调用函数。但它只会在第一次被调用,然后才被调用。是否有像iOS的viewWillAppear这样的事件函数。我正在使用'initialize'事件函数,它只被调用一次。请帮忙。

查看:

Ext.define('Abc.view.abc', {
 extend: 'Ext.List',
 xtype: 'runningList',
 requires: ['Abc.store.InstancesStore','Ext.data.proxy.JsonP',],

config: {
title: 'Running',
id: 'instanceList',/*
itemTpl: '<div class="serached_listview">'+ 
        '<div>{key}  {key} </div>' +
        '<div><b>{key}</b> </div>' +
        '<div>  {key}</div>' +
        '</div>'
        ,*/
        store: 'RunningInstanceStore',
           listeners: [{
                fn: 'initialize',
                 event: 'initialize'
            }
    ]
  }
});

控制器:

 Ext.define("Abc.controller.InstancesController", {
extend: 'Ext.app.Controller',
requires: [ 'Ext.data.JsonP','Ext.device.Connection'],
config: {
    refs: { 
        main: 'mainpanel',
                     Instances: '#instanceList',
        ListView: 'runningList'
    },
    control: {
        Instances: {
            initialize: 'initializePanel',
            activate:'initializePanel'
        },
        "runningInstancesList": {
            disclose: 'listViewAccessoryTapped',
            itemtap: 'listViewTapped'
        }
    }
},
listViewAccessoryTapped:  function(view, index, item, e) {
    if(Ext.device.Connection.isOnline())
        console.log('Internet connection is available.');
    else
        console.log('Internet connection is not available.');

},
listViewTapped:  function(view, index, item, e) {




},

initializePanel: function() { 
    console.log('Hi');     **////////////////Called only once...**

}
});

2 个答案:

答案 0 :(得分:0)

在ExtJS中有component.beforeactivate,每次激活组件之前都会触发

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.AbstractComponent-event-beforeactivate

然而,在Touch中,似乎只有container.activate,看起来它在激活子组件后被触发

http://docs.sencha.com/touch/2-1/#!/api/Ext.Container-event-activate

答案 1 :(得分:0)

其中一个事件处理程序(而不是初始化)可以帮助您:


http://docs.sencha.com/touch/2-1/#!/api/Ext.Component-event-painted

显示
http://docs.sencha.com/touch/2-1/#!/api/Ext.Component-event-show

理想情况下,这些事件应该在这样的控制器中处理(多种方式之一)

        '#instanceList': {
            show        : 'onListShow'
        }

但您可以选择将监听器添加到您的视图中:

Ext.define('Abc.view.abc', {
  extend: 'Ext.List',
  xtype: 'runningList',
  requires: ['Abc.store.InstancesStore','Ext.data.proxy.JsonP',],

  config: {
    title: 'Running',
    id: 'instanceList',
    store: 'RunningInstanceStore',
    listeners: {
      show  : function(me, opts){
        // Do whatever you want here
      }
    }
  }
});