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

时间:2012-12-08 05:04:16

标签: javascript extjs extjs4 extjs4.1

我遇到一些问题我无法在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();


}

3 个答案:

答案 0 :(得分:6)

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

示例:

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

答案 1 :(得分:0)

试试这个:

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){

}
});

答案 2 :(得分:-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() {
    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){           
  }
});