Cannot read property ‘indexOf’ of null
let result = this.pages1.values.filter(row => {//this.pages1.values this is all the data in the table
// search the content of that column, here search the content of the name, id and other columns
return row.name.indexOf(this.search1) > -1
|| row.id.indexOf(this.search1) > -1
|| row.code.indexOf(this.search1) > -1
|| row.note.indexOf(this.search1) > -1;
});
error message:
TypeError: Cannot read property 'indexOf' of null
at app.43208ea5.js:1
at Array.filter (<anonymous>)
at o.sousuo (app.43208ea5.js:1)
at click (app.43208ea5.js:1)
at it (chunk-vendors.ffbff91e.js:34)
at o.n (chunk-vendors.ffbff91e.js:34)
at it (chunk-vendors.ffbff91e.js:34)
at o.In.e.$emit (chunk-vendors.ffbff91e.js:34)
at o.handleClick (chunk-vendors.ffbff91e.js:1)
at it (chunk-vendors.ffbff91e.js:34)
means the indexOf when used to determine the front row. Name the error, all you need to use to determine whether these is empty before indexOf
if(row.name! =null||row.id! = null | |…). This is too much trouble
We can write a method:
contains(prop, str) {
if (prop === null || prop === undefined) {
return false;
} else {
return prop.indexOf(str) > -1;
}
},
and then modify the wording, I here the VUE method and invoke the contains is to add this, if it is js will remove the this
let result = this.pages1.values.filter(row => {
return this.contains(row.name, this.search1)
|| this.contains(row.id, this.search1)
|| this.contains(row.code, this.search1)
|| this.contains(row.note, this.search1)
});
Similar Posts:
- [Solved] DOM parsing XML Error: Content is not allowed in prolog
- Resource interpreted as Stylesheet but transferred with MIME type text/html: css not work
- [Solved] appium Error: A new session could not be created
- Spring Boot UrlResource loading classpath error: unknown protocol: classpath
- Causes and solutions of xxx.indexof is not a function problem
- [Solved] Webpack4 output configuration filename chunkash error
- The use of Hibernate / JPA getsingleresult reports an exception noresult xception:No entity found for query
- Vue Error: Error in render: “TypeError: Cannot read properties of null (reading ‘xxx’)” found in
- System.Data.SqlTypes.SqlNullValueException: ‘Data is Null. This method or property cannot be called on Null values.’
- JS Uncaught TypeError: Cannot read property ‘toLowerCase’ of undefined