' Uncaught TypeError的实例:无法读取属性'包含' of null'

时间:2017-12-15 00:51:01

标签: javascript json

出于某种原因,我在这里的if语句,偶尔会抛出以下错误,我无法弄清楚原因:

    /**
 * Identify if a year is a leap year or not
 *
 * @param    integer    $year    The year to test
 * @return    boolean            TRUE if the year is a leap year, otherwise FALSE
 */
public static function isLeapYear($year)
{
    return ((($year % 4) == 0) && (($year % 100) != 0) || (($year % 400) == 0));
}
/**
 * Return the number of days between two dates based on a 360 day calendar
 *
 * @param    integer    $startDay        Day of month of the start date
 * @param    integer    $startMonth        Month of the start date
 * @param    integer    $startYear        Year of the start date
 * @param    integer    $endDay            Day of month of the start date
 * @param    integer    $endMonth        Month of the start date
 * @param    integer    $endYear        Year of the start date
 * @param    boolean $methodUS        Whether to use the US method or the European method of calculation
 * @return    integer    Number of days between the start date and the end date
 */
private static function dateDiff360($startDay, $startMonth, $startYear, $endDay, $endMonth, $endYear, $methodUS)
{
    if ($startDay == 31) {
        --$startDay;
    } elseif ($methodUS && ($startMonth == 2 && ($startDay == 29 || ($startDay == 28 && !self::isLeapYear($startYear))))) {
        $startDay = 30;
    }
    if ($endDay == 31) {
        if ($methodUS && $startDay != 30) {
            $endDay = 1;
            if ($endMonth == 12) {
                ++$endYear;
                $endMonth = 1;
            } else {
                ++$endMonth;
            }
        } else {
            $endDay = 30;
        }
    }
    return $endDay + $endMonth * 30 + $endYear * 360 - $startDay - $startMonth * 30 - $startYear * 360;
}

以下;我也尝试反过来重写它仍然会引发' Uncaught TypeError: Cannot read property 'includes' of null ',但有时它会完美无误地运行?

.includes

更多相关代码

if (['en','or', 'de', 'ur', 'bn', 'ch'].some(original_language => item.original_language.includes(original_language))) {
    // content happens
}

1 个答案:

答案 0 :(得分:2)

.original_language null item data.content data.content console.log item(s).original_language .original_languageif (['en','or', 'de', 'ur', 'bn', 'ch'].some(original_language => item.original_language && item.original_language.includes(original_language))) { // content happens } 1}}没有<td><a href="URL1"><img src="IMG1"></a>TXT1</td> <td><a href="URL2"><img src="IMG2"></a>TXT2</td> <td><a href="URL3"><img src="IMG3"></a>TXT3</td>

我觉得你需要检查1是否存在(并且它是一个数组)。

0