如何在 extjs4.1 的控制器中声明全局变量?

Posted

技术标签:

【中文标题】如何在 extjs4.1 的控制器中声明全局变量?【英文标题】:How can i declare global variable in the controller in extjs4.1? 【发布时间】:2012-12-08 05:04:16 【问题描述】:

我遇到了一些问题,我无法在 extjs 4.1 控制器中声明全局变量,如果有人可以帮助我如何声明它。我不知道如何声明它 这是我的代码

Ext.define('Ext4Example.controller.poscontroller', 
    extend: 'Ext.app.Controller',    
    //models: ['Vat','Rebate','Customer','Product','Invoice','Item','Order','Paymethod'],
    stores: ['InvoiceIdFromSession','Vats','Rebates','Customers','Products','Invoices','Items','Paymethods'], //'Orders', ,'InvoiceIdFromSession','Products'  
    id : 'poscontroller',
    views   : ['stock.SaleWindow','stock.ItemForm2','stock.ItemsGrid','stock.CalculationForm'],
    refs: [
        ref: 'itemForm',
        selector: 'form'
    ],
    init: function() 
        this.control(
            'itemsgrid': 
                removeitem: this.removeUser
            ,
            'salewindow button[action=resetAll]': 
                click: this.resertform
            ,            
            'salewindow button[action=saveOrder]' : 
                click : this.onsaveOrder
            ,
            'salewindow button[action=PDF]' : 
                click : this. pdfreport
            
        );
    ,

    onsaveOrder : function(button)
            // i want declare this variable to global variable  

            var  itemform  = Ext.getCmp('itemform2');
            var  calculation_Form =Ext.getCmp('calculation-form');
            var ItemFrmdata = itemform.getForm().getValues(); 
            var calcFrmdata = calculation_Form.getForm().getValues();



【问题讨论】:

【参考方案1】:

就像您设置idviews 或任何其他属性一样。您只需要知道它们命名为属性而不是变量。

示例:

//...
stores: ['InvoiceIdFromSession','Vats'], 
booleanVariable: true, 
stringVariable: 'demo',
floatVariable: .6,
objectVariable:  demo: 'test' , 
id : 'poscontroller',
//...

【讨论】:

投反对票的人能否说明投反对票的原因?答案没有错,并且是在 OP 添加他使用的解决方案之前发布的 抱歉,实际上我是***的新用户。【参考方案2】:

试试这个:

Ext.define('Ext4Example.controller.poscontroller', 
extend: 'Ext.app.Controller',
models: [
    'Vat',
    'Rebate',
    'Customer',
    'Product',
    'Invoice',
    'Item',
    'Order',
    'Paymethod'
],
stores: [
    'InvoiceIdFromSession',
    'Vats',
    'Rebates',
    'Customers',
    'Products',
    'Invoices',
    'Items',
    'Paymethods'
], //'Orders', ,'InvoiceIdFromSession','Products'
id : 'poscontroller',
views : [
    'stock.SaleWindow',
    'stock.ItemForm2',
    'stock.ItemsGrid',
    'stock.CalculationForm'
],
refs: [
    ref: 'itemForm',
    selector: 'form'
],

/*These are Global variables for this controller,
Now you can get and set these variable according to your need*/
config:
    itemform  : Ext.getCmp('itemform2'),
    calculation_Form : Ext.getCmp('calculation-form'),
    ItemFrmdata : this.getItemform().getForm().getValues(),  // for get declared Variable
    calcFrmdata : this.getCalculation_Form().getForm().getValues()  // for get declared Variable
,
init: function() 

    this.control(
        'itemsgrid': 
            removeitem: this.removeUser
        ,
        'salewindow button[action=resetAll]': 
            click: this.resertform
        ,
        'salewindow button[action=saveOrder]' : 
            click : this.onsaveOrder
        ,
        'salewindow button[action=PDF]' : 
            click : this. pdfreport
        
    );
,
onsaveOrder : function(button)


);

【讨论】:

【参考方案3】:

我终于做到了.....

Ext.define('Ext4Example.controller.poscontroller', 
  extend: 'Ext.app.Controller',    
  //models: ['Vat','Rebate','Customer','Product','Invoice','Item','Order','Paymethod'],
  stores: ['InvoiceIdFromSession','Vats','Rebates','Customers','Products','Invoices','Items','Paymethods'], //'Orders', ,'InvoiceIdFromSession','Products'  
  id : 'poscontroller',
  views : ['stock.SaleWindow','stock.ItemForm2','stock.ItemsGrid','stock.CalculationForm'],
  refs: [
    ref: 'itemForm',
    selector: 'form'
  ],
  init: function() 
    itemform  = Ext.getCmp('itemform2');
    calculation_Form = Ext.getCmp('calculation-form');
    ItemFrmdata = itemform.getForm().getValues(); 
    calcFrmdata = calculation_Form.getForm().getValues();
    this.control(
      'itemsgrid': 
        removeitem: this.removeUser
      ,
      'salewindow button[action=resetAll]': 
        click: this.resertform
      ,            
      'salewindow button[action=saveOrder]' : 
        click : this.onsaveOrder
      ,
      'salewindow button[action=PDF]' : 
        click : this. pdfreport
      
    );
  ,

  onsaveOrder : function(button)           
  
);

【讨论】:

以上是关于如何在 extjs4.1 的控制器中声明全局变量?的主要内容,如果未能解决你的问题,请参考以下文章

js中怎么把一个变量变成全局变量

在目标 c 中使用全局变量

如何在打字稿中声明全局变量

如何在android应用程序中声明全局变量? [复制]

如何在 VBA 中声明一个全局变量?

如何在 Angular 2 / Typescript 中声明全局变量? [关闭]