无法读取布尔字段的null属性'AllowOverride'

时间:2019-12-11 05:44:17

标签: arraylist angular-material angular7

我在上面有类似的回复 enter image description here

我需要对此框

const masterSettingResponse = {
            masterSMS: {
                allowOverRide: setting.MasterSMS.AllowUserOverride,
                smsEnabled: setting.MasterSMS.SMSEnabled,
                smsUrl: setting.MasterSMS.SMSURL,
                accessToken: setting.MasterSMS.AccesToken,
                smsLogUrl: setting.MasterSMS.SMSLogUrl,
                clientId: setting.MasterSMS.ClientId,
            },
            masterEmail: {
                allowOverRide: setting.MasterEmail.AllowOverride,
                emailEnabled: setting.MasterEmail.EmailEnabled,
                emailLogUrl: setting.MasterEmail.EmailLogUrl,
                accessToken: setting.MasterEmail.AccessToken,
                emailUrl: setting.MasterEmail.EmailUrl,
                clientId: setting.MasterEmail.ClientId,
            },
            masterGeneralSetting: {
                isActive: setting.MasterGeneralSetting.IsActive,
                portalSessionTimeout: setting.MasterGeneralSetting.PortalSessionTimeout,
                appSessionTimeout: setting.MasterGeneralSetting.AppSessionTimeout,
            },
        };

        return masterSettingResponse;

来到MasterEmail时,我收到一个'AllowOverride'空异常。 但是,它是布尔属性。如果数据不可用,我需要将“ masterEmail”显示为空。如何克服例外?

1 个答案:

答案 0 :(得分:1)

您正在尝试从空对象访问属性。为此添加检查,以解决您的问题。

const masterSettingResponse = {
            masterSMS: {
                allowOverRide: (setting.MasterSMS ? setting.MasterSMS.AllowUserOverride : null),
                smsEnabled: (setting.MasterSMS ? setting.MasterSMS.SMSEnabled : null),
                smsUrl: (setting.MasterSMS ? setting.MasterSMS.SMSURL : null),
                accessToken: (setting.MasterSMS ? setting.MasterSMS.AccesToken : null),
                smsLogUrl: (setting.MasterSMS ? setting.MasterSMS.SMSLogUrl : null),
                clientId: (setting.MasterSMS ? setting.MasterSMS.ClientId : null),
            },
            masterEmail: {
                allowOverRide: (setting.MasterEmail ? setting.MasterEmail.AllowOverride : null),
                emailEnabled: (setting.MasterEmail ? setting.MasterEmail.EmailEnabled : null),
                emailLogUrl: (setting.MasterEmail ? setting.MasterEmail.EmailLogUrl : null),
                accessToken: (setting.MasterEmail ? setting.MasterEmail.AccessToken : null),
                emailUrl: (setting.MasterEmail ? setting.MasterEmail.EmailUrl : null),
                clientId: (setting.MasterEmail ? setting.MasterEmail.ClientId : null),
            },
            masterGeneralSetting: {
                isActive: (setting.MasterGeneralSetting ? setting.MasterGeneralSetting.IsActive : null),
                portalSessionTimeout: (setting.MasterGeneralSetting ? setting.MasterGeneralSetting.PortalSessionTimeout : null),
                appSessionTimeout: (setting.MasterGeneralSetting ? setting.MasterGeneralSetting.AppSessionTimeout : null),
            },
        };