问题
I am getting this error on line:
return filter ? value.filter(element => element.type.toLowerCase().indexOf(filter.toString().toLowerCase()) != -1) : value;
when element.type is empty string (filtering empty column). How to fix this?
回答1:
As the message states: element.type
is undefined
. Add a check on that in your filter
call. Something like this, what you put depends on what you are expecting back and I can only guess at that.
return filter
? value.filter(element => element.type && element.type.toLowerCase().indexOf(filter.toString().toLowerCase()) != -1)
: value;
回答2:
This error itself gives the solution as the value passed to change into lowercase is null or undefined. To solve such errors, put the statements for the data to be passed in an 'if' statement.
Like :
if(somevalue != null || somevalue != undefined)
{ ... }
Putting the statements inside if statement solved my issue.
回答3:
Well said, error itself gives the solution as the value passed to change into lowercase is null or undefined.
Just add to your line of code, where you see error coming
if(somevalue != null || somevalue != undefined)
{ ... }
来源:https://stackoverflow.com/questions/42542137/typescript-cannot-read-property-tolowercase-of-undefined