无法监听控制器中的更改事件

是Ext JS社区的新成员。在这里,我想将更改事件应用于子组件“ textfield”。 我已经在控制器中指定了“ onChangeSealNumber”功能。但这并没有被解雇。 有人可以帮我吗?

我尝试了许多方法,但是,如果我在更改时传递匿名函数,它将起作用。但是,当我们明确指定为“ onChangeSealNumber”时,它将无法正常工作。

查看文件

/**
 * Search Form Panel View.
 * @class 'BulkTransaction.view.searchfrom.SearchForm'
 */

Ext.define('BulkTransaction.view.searchform.SearchForm',{

  extend: 'Ext.container.Container',requires: [
    'Common.view.widget.RepeatingWidgetGroup','BulkTransaction.view.storagelocation.Storagelocation','BulkTransaction.view.searchform.SearchFormController',],alias: 'widget.searchform',controller: 'searchformcontroller',items: [
    {
      xtype: 'basepanel',width: '100%',reference: 'searchform',header: false,items: [
        {
          width: '100%',xtype: 'connect-repeating-widget-group',bind: {
            store: '{topSealNumbers}'
          },bindReference: 'topSealNumbers',widgetconfig: {
            xtype: 'textfield',fieldLabel: BulkTransaction.util.Constants.searchForm.topSealNumbers,allowBlank: false,bind: '{topSealNumbers.searchCriteria}',cls: 'seal-number-field',listeners: {
              change: 'onChangeSealNumber'
            }
          }
        }
      ]
    }
  ]
});

控制文件


/** 
 * Controller containing the methods implementing functionality 
 * related to search form
*/
Ext.define('BulkTransaction.view.searchform.SearchFormController',{
  extend: 'Ext.app.ViewController',alias: 'controller.searchformcontroller',init: function () {
      const me = this;
      const viewModel = me.getViewModel();
      viewModel.bind({
        bindTo: '{topSealNumbers}',deep: true
      },me.onSearchCriteriaChange,me);
  },/**
   * Handle change to the sealnumber details
   * @private
   */
  onSearchCriteriaChange: function (store) {
    const me = this;
    let searchCriteriaRecords;
    searchCriteriaRecords = store.queryBy(rec =>{
      if (!Ext.isEmpty(rec.get('searchCriteria').trim())) {
        return rec;
      }
    });

    this.fireEvent('toggleSearchButton',searchCriteriaRecords.length > 0);

  },onChangeSealNumber(elm) {
    const me = this,view = me.getView();
  }

});

zhuhui34555 回答:无法监听控制器中的更改事件

在控制器中,您需要创建一个名为onChangeSealNumber的函数

Ext.define('BulkTransaction.view.searchform.SearchFormController',{
    extend: 'Ext.app.ViewController',alias: 'controller.searchformcontroller',onChangeSealNumber: function(field,newValue,oldValue,eOpts) {
        //do something here

    },})
,

您可以尝试(MyApp-您的应用程序名称): listeners: {change: MyApp.app.getController('SearchFormController').onChangeSealNumber()} 但是对我来说,这不是与控制器一起工作的好方法。更好地添加到控制器(在init内部):

init: function (application) {  
  this.control({
    "searchform textfield": {
      change: this.onChangeSealNumber
    },});
}

对于标识符,我不确定,因为通常使用itemId和名称

(like    `"#myItemId textfield[name=MyFieldName]"`    )
本文链接:https://www.f2er.com/3029188.html

大家都在问