我有一個xPages應用程序在javascript中使用全局變量。全局變量是一個NotesDocument。當xPage加載時,它會調用一些Java代碼來填充全局Javascript var。全局Javascript var變爲空
稍後我從該全局變量中提取一些信息,一切都很好。稍後在代碼中,我嘗試從試圖訪問該全局變量的Javascript庫中運行一個函數,該變量爲空。我不知道爲什麼。沒有其他更新該全局變量。
有人可以指出我的方向來解決這個問題嗎?
//This is the script library function that throws the null error:
var revoPayments =
{
// Calculate if the occupant should see the Revo Pay My Bill Link in the occ navigator
"renderPayMyBillRevo" : function()
{
var result = false;
try
{
// THIS IS WHERE THE GLOBAL VAR IS NULL
if(parseInt(gUserOccupantProfile.getShowRevoLink()) == -1)
result = true;
} catch (e)
{
print(e.message);
}
print("result: " + result);
return result;
}
}
//This is the calling javascript from the xPage which works fine pulling all the values etc.
if(gUserOccupantProfile && gUserOccupantProfile !== "null" && gUserOccupantProfile !== "undefined")
{
// ALL THESE VALUES ARE SET BECAUSE IT'S A VALID OBJECT
sessionScope.put("OccupantUNID", gUserOccupantProfile.getDocUNID());
sessionScope.put("Tenant_ID", gUserOccupantProfile.gettenant_id());
sessionScope.put("UnitRefNo", gUserOccupantProfile.getUnitRefNo());
sessionScope.put("Resident", gUserOccupantProfile.getResident());
sessionScope.put("FirstName", gUserOccupantProfile.getFirstName());
sessionScope.put("LastName", gUserOccupantProfile.getLastName());
sessionScope.put("CurrentUser", gUserOccupantProfile.getFirstName() + " " + gUserOccupantProfile.getLastName());
sessionScope.put("PropertyAddress", gUserOccupantProfile.getPropertyAddress());
var tempStr = gUserOccupantProfile.getcurrent_balance();
tempStr = tempStr.replace("$", "");
tempStr = tempStr.replace(",", "");
sessionScope.put("Current_Balance", tempStr);
sessionScope.put("PropertyNo", gUserOccupantProfile.getPropertyNo());
sessionScope.put("PropertyName", gUserOccupantProfile.getPropertyName());
sessionScope.put("LastPaymentDate", gUserOccupantProfile.getLast_payment_date());
sessionScope.put("LastPaymentAmount", gUserOccupantProfile.getPayment_amount());
gAPropertyProfile = eStarService.getPropertyProfile(sessionScope.get("PropertyNo"));
// 09.15.2014 - Steven Rieger : added code to disable pay my bill for separate properties
// Default is to always display the option.
if(gAPropertyProfile.getDisablePayMyBill().toLowerCase() == "yes")
sessionScope.put("renderPayMyBill", false);
else
sessionScope.put("renderPayMyBill", true);
sessionScope.put("renderStatements", myEStatements.renderStatements());
print("Before RenderRevo");
// THIS LINE FAILS BECAUSE IN THE SCRIPT LIBRARY CODE (SEE ABOVE) THE
// GLOBAL VAR IS NULL
sessionScope.put("renderPayMyBillRevo", revoPayments.renderPayMyBillRevo());
print("After RenderRevo");
// sessionScope.put("dialogOopsTitle", "Debug!");
// sessionScope.put("dialogOopsMessage", "gotLogEntry: " + gotLogEntry);
// var dialogOops = getComponent("dialogOops");
// dialogOops.show();
}
快速提示:您可能想要將'gUserOccupantProfile!==「null」&& gUserOccupantProfile!==「undefined」'更改爲'gUserOccupantProfile!== null && gUserOccupantProfile!== undefined' 。 –
gUserOccupantProfile是在我的腳本庫頂部定義的全局(未在代碼中顯示) – Bitwyse1
我在線上閱讀了一些內容,如果它們是字符串值「null」或「undefined」,並且(gUserOccupantProfile)會捕獲null或未定義的對象? – Bitwyse1