Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

254
Views
No capturado (en promesa) TypeError: this.getChildrem no es una función

tengo lo siguiente:

 getitem: function(){ $this.users = $data.data; $this.users = $this.users.filter( function(item) { if(item.status === true ) { if( item.children.length > 0 ){ item.children = this.getChildrem(item.children, true); } return item; }}); }, getChildrem: function(node, estatus){ $children = node.filter( function(item) { if(item.status === estatus ) { if( item.children.length > 0 ){ item.children = this.getChildrem(item.children, estatus); } return item; }}); return $children; },

esta es una función recursiva simple, solo obtengo todos los elementos (padres e hijos) con el estado 'verdadero' pero tengo este error:

 Uncaught (in promise) TypeError: this.getChildrem is not a function

¿Por qué estoy recibiendo este error?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Cuando define la función que pasa a node.filter , this contexto cambia. Puede evitar esto pasando una función de flecha en su lugar, o usando .bind .

Entonces, en lugar de

 getChildrem: function(node, estatus){ $children = node.filter( function(item) {

prueba esto:

 getChildrem: function(node, estatus){ $children = node.filter( (item) => {
about 4 years ago · Juan Pablo Isaza Report

0

Es porque la función de devolución de llamada está usando el alcance global, mientras que ese objeto está en un alcance diferente

 var obj = { test(){ (function(){console.log(this);})(); //Prints global object (()=>{console.log(this);})(); // prints local object } }

Debería cambiar esa función normal a una función de flecha, porque la función de flecha capturará el alcance adjunto

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!