JavaScript Pentaho 中的错误 - 无法调用 null 的方法 "toUpperCase"

JavaScript Error in Pentaho - Cannot call method "toUpperCase" of null

// 将所有字母设置为大写

var str = ae_a_asset_e$manufacture_code.toUpperCase();
var str2 = ae_a_asset_e$serial_no.toUpperCase();
var str3 = ae_a_asset_e$manu_part_number.toUpperCase();
var str4 = ae_a_asset_e$region_code.toUpperCase();
var str5 = ae_a_asset_e$fac_id.toUpperCase();

知道如何解决这个问题吗?我认为必须有一种方法可以说明 if value = null 然后不用担心。

首先你得想想有些值是null对不对,比如ae_a_asset_e$manufacture_code.

如果它们可以 null 您可以像这样以安全的方式访问它们(根据需要将此代码扩展到所有其他变量):

var str = ae_a_asset_e$manufacture_code ? ae_a_asset_e$manufacture_code.toUpperCase() : "";

如果它们不能 null 那么,你应该先检查你的数据完整性然后 运行 这个脚本(假设它们永远不会 null)。