Javascript 运行时错误:类型错误:无法获取未定义或空引用的属性'split'



我收到此运行时错误:

类型错误:无法获取未定义或空引用的属性"拆分" at $scope.typeFilter (http:////*/js/controllers.js:124:9)

$scope.typeFilter = function(type){
var typestring = type.Types;
var typelist = typestring.split(", ");
}

当你调用函数时,你可能会传递没有类型属性的参数。因此,它将为空或未定义。 为避免错误,您可以先检查该类型属性是否具有某些值。

$scope.typeFilter = function(type){
if(type.types) {
var typestring = type.Types;
var typelist = typestring.split(", ");
}
}

最新更新