在一种方法中访问变量,该方法在其他方法中使用

时间:2018-05-03 10:04:52

标签: javascript salesforce-lightning

我想从doinit访问变量以保存开销方法。我试图在saveExpense中访问临时变量。控制台正在抛出未定义的

 ({
 doInit: function(component, event, helper) {
    helper.getMatrix(component, event);
    helper.getRolesConverted(component, event);
    var temp=0;
},
saveExpenses: function(component, event, helper) {
     helper.saveExpenses(component, event);
     console.log('temp value ',temp);
},
});

1 个答案:

答案 0 :(得分:0)

var temp;
({
 doInit: function(component, event, helper) {
    helper.getMatrix(component, event);
    helper.getRolesConverted(component, event);
    temp=0;
},
saveExpenses: function(component, event, helper) {
     helper.saveExpenses(component, event);
     console.log('temp value ',temp);
},
});