2017-05-04 61 views
2

我有一个关于ExtJS控制器的问题。我的代码:使用extjs控制器

Ext.define('app.controller.Clients.Clients', { 
    extend: 'Ext.app.Controller', 
    stores: ['Clients.Clients'], 
    models: ['Clients.Clients'], 
    views: ['Clients.Clients'], 
    init: function() { 
     this.control({ 
      'gridClients button[action=deleteClient]': { 
       click: this.onButtonClickDelete 
      }, 
      'gridClients button[action=refreshClients]': { 
       click: this.onButtonClickRefresh 
      }, 
      'gridClients button[action=printClients]': { 
       click: this.onButtonClickPrint 
      } 
     }) 
    }, 
    onButtonClickDelete: function(button, e, options) { 
     alert('DELETE?'); 
    }, 
    onButtonClickRefresh: function(button, e, options) { 
     alert('REFRESH?'); 
    }, 
    onButtonClickPrint: function(button, e, options) { 
     alert('PRINT?'); 
    } 
}); 

我要引用一个名为“gridClients”网格,我想知道是否有任何的方式来创建驱动程序文件中的变量...

我将参考一个名为'gridClients'的网格,并且我想知道是否有任何方法在驱动程序文件内创建一个变量来引用该网格。

例子,我想类似的东西:

Var Grid = Ext.ComponentQuery.query (#gridClients) [0]; 

而且使用这样的:

OnButtonClickRefresh: function (button, e, options) { 
     Grid.getStore(). Load(); 
    } 

我真的不知道从哪里声明VAR ...

回答

1

在控制器,您预计与refs工作。例如:

Ext.define('app.controller.Clients.Clients', { 
    extend: 'Ext.app.Controller', 
    stores: ['Clients.Clients'], 
    models: ['Clients.Clients'], 
    views: ['Clients.Clients'], 
    init: function() { 
     ... 
    }, 
    refs:[{ 
     ref:'clientsGridExample', 
     selector: '#gridClients' 
    }], 
    OnButtonClickRefresh: function (button, e, options) { 
     this // inside a controller, these functions are scoped to controller 
      .getClientsGridExample() // refs are automatically converted to getter methods 
      .getStore().load(); // Do whatever you want to do 
    } 
}); 
+0

太棒了! 它的工作原理,感谢您在阅读文档后向我展示'refs'的用法,我理解它的用法。 –

0

在OnButtonClickRefresh监听器中,您可以像这样得到网格:

var grid = button.up("grid"); 

链接到fiddle

1

这是很清楚的,如果你检查Ext.app.Controller documentation

您可以在您的控制器中设置refs并使用生成的getter来获取所需的网格。例如,如果您的ref的值为clientsGrid,则ExtJS将创建获取者getClientsGrid()

`

Ext.define('app.controller.Clients.Clients', { 
    extend: 'Ext.app.Controller', 
    stores: ['Clients.Clients'], 
    models: ['Clients.Clients'], 
    views: ['Clients.Clients'], 

    refs: [ 
     { ref: 'grid', selector: '#gridClients' } 
    ],  

    init: function() { 
     this.control({ 
      'gridClients button[action=deleteClient]': { 
       click: this.onButtonClickDelete 
      }, 
      'gridClients button[action=refreshClients]': { 
       click: this.onButtonClickRefresh 
      }, 
      'gridClients button[action=printClients]': { 
       click: this.onButtonClickPrint 
      } 
     }) 
    }, 
    onButtonClickDelete: function(button, e, options) { 
     this.getGrid().doSomething(); 
    }, 
    onButtonClickRefresh: function(button, e, options) { 
     alert('REFRESH?'); 
    }, 
    onButtonClickPrint: function(button, e, options) { 
     alert('PRINT?'); 
    } 
}); 

`

相关问题