当我在下面的代码中定义的console.log
函数中运行initialize
时,如下所示:
console.log("Checking for Value_Of_Process_Type in Initialize Function ! :" +Value_Of_Process_Type);
console.log("Checking for Todays Date in Initialize Function ! :" +TodaysDate);
我为这两个变量得到undefined
。但是,我在console.log
函数的单击处理程序中定义了以下processEmployeeData
中的两个变量的值:
console.log("Value_Of_Process_Type and Value_Of_TodaysDate are as follows :"+Value_Of_Process_Type+" and "+TodaysDate);
所以基本上,我的变量没有从函数processEmployeeData
传递到initialize
函数。我可以遵循任何其他方法来实现这一点或我正在做的任何错误吗?
function EmployeePage() {
var self = this;
this.employeeData = function (employee_number_) {
// Initialize the page
this.initialize = function () {
var employee_number = AppManager.selectedData["employee_number"];
console.log("employee_number By calling page:" +employee_number);
var Value_Of_Process_Type = AppManager.selectedData["my_page.Process_Type"];
var TodaysDate = AppManager.selectedData["my_page.date_value"];
console.log("Checking for Value_Of_Process_Type in Initialize Function ! :" +Value_Of_Process_Type); //outputs undefined here
console.log("Checking for Todays Date in Initialize Function ! :" +TodaysDate); //outputs undefined here
};
this.processEmployeeData = function (collection_) {
$("#myPanel").on('rowclick',function(event){
row = event.args.rowindex;
datarow = $("#myPanel").jqxGrid('getrowdata', row);
var response = JSON.stringify(datarow,null,10);
var Process_Type = datarow["processType"];
AppManager.selectData("my_page.Process_Type", Process_Type);
var Value_Of_Process_Type = AppManager.selectedData["my_page.Process_Type"];
var TodaysDate = datarow["date_value"];
AppManager.selectData("my_page.date_value", TodaysDate);
var Value_Of_TodaysDate = AppManager.selectedData["my_page.TodaysDate"];
console.log("Value_Of_Process_Type and Value_Of_TodaysDate are as follows :"+Value_Of_Process_Type+" and "+TodaysDate); // Prints the values
});
};
答案 0 :(得分:0)
Javascript中的函数主要用作另一种类型的对象。因此,您可以为函数指定变量;在您的情况下,将声明更改为this.Value_Of_Process_Type=AppManager.selectedData["my_page.Process_Type"];
应该允许您使用this.Value_Of_Process_Type
在函数的其他位置访问它。