2014-12-02 60 views
0

我想从嵌套对象内部获取父对象的函数。extJs从嵌套对象访问父函数

Ext.define('SearchPanel', { 
     extend: 'common.Panel', 
     header: false, 
     xtype: 'search-panel', 
     layout: 'fit', 
     items: [ 
      { 
       xtype: 'form-panel', 
       items: [ 
        { 
         xtype: 'datetimefield', 
         itemId: 'from', 
         fieldLabel: T('From'), 
         dateConfig: { 
          itemId: 'startDate', 
          value: new Date(), 
          validator: ValidateRange//trying to access "external" function here 
         }, 
         timeConfig: { 
          value: '12:00 AM', 
          itemId: 'startTime', 
          validator: ValidateRange//trying to access "external" function here 
         } 
        } 
       ], 
       ValidateRange: //the function I'm trying to call from nested object 
        function (value) { 
        //validation logic 
        } 


      } 
     ], 


    }); 

它不起作用。我收到错误:Uncaught ReferenceError:ValidateRange未定义

+0

尝试使用this this.up()。up()。 ValidateRange – 2014-12-02 17:11:05

回答

2

这是不可能的,您必须使用在类之外定义的方法。我们可以使用一个静态成员和引用此:

Ext.define('SearchPanel', { 
    statics: { 
     validateRange: function() {} 
    }, 
    items: { 
     someRandomChild: { 
      validator: function() { 
       return SearchPanel.validateRange.apply(this, arguments); 
      } 
     } 
    } 
}); 

你必须把它包装成另一个功能造成SearchPanel当类是ExtJS的“定义”没有定义。