4

我遇到了一些问题,如果有人可以帮助我,我无法在 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();


}
4

3 回答 3

7

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

例子:

//...
stores: ['InvoiceIdFromSession','Vats'], 
booleanVariable: true, 
stringVariable: 'demo',
floatVariable: .6,
objectVariable: { demo: 'test' }, 
id : 'poscontroller',
//...
于 2012-12-10T07:50:47.087 回答
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){

}
});
于 2016-08-13T09:09:40.673 回答
-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){           
  }
});
于 2013-01-28T11:55:43.797 回答