Cannot read property 'length' of undefined in the component

topic description

Cannot read property "length" of undefined cannot find length in the component

related codes

/ / Please paste the code text below (do not replace the code with pictures)
1, let index = this.$utils.findObjIndex (this.name, "datum_customer_shareholder_id", p.datum_customer_shareholder_id)

          if (index > -1) {
            p.name = this.name[index].real_name
          }
          
          
          2:export const findObjIndex = (array, attr, val) => {

for (let I = 0; I

if (array[i][attr] === val) { return i }

}
return-1
}
3,
error:
clipboard.png

:

clipboard.png

what result do you expect? What is the error message actually seen?

answer

Apr.06,2022

the value of this.name is undefined, execute this.name.length, and throw this error

do a data monitoring in the function findObjIndex, or filter the data when the function is used

Menu