• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

131
Views
El objeto anidado Vue JS lodash findKey con notación de puntos devuelve indefinido

Estoy tratando de obtener un valor para una clave de objeto anidado de una matriz de elegibilidad que tengo, pero obtengo un valor indefinido por algún motivo y necesito saber qué me estoy perdiendo.

Dada la siguiente matriz:

 const eligibilityCriteria = [ { field: 'loan.amount', operator: '>=', value: 1000 }, { field: 'loan.term', operator: '>=', value: 1 }, { field: 'applicant.birthday', operator: '>=', value: 40 }, { field: 'applicant.isHomeowner', operator: '==', value: false } ]

Necesito encontrar loan.amount del préstamo de un objeto anidado y extraer su valor:

Mi gran objeto anidado es (procedente de la tienda)

 application: { meta: { brand: '', version: '', affiliate: '', affiliate_full: '', campaign: '', client_hostname: '', client_href: '', client_origin: '', client_useragent: '', client_ip: '127.0.0.1', icicle_hash: '' }, loan: { amount: 500, term: null, purpose: null } }

Mi función en este momento es:

 checkEligibility () { const eligibilityCriteria = [ { field: 'loan.amount', operator: '>=', value: 1000 }, { field: 'loan.term', operator: '>=', value: 1 }, { field: 'applicant.birthday', operator: '>=', value: 40 }, { field: 'applicant.isHomeowner', operator: '==', value: false } ] for (const [index, offer] of this.datasets.offers.entries()) { const eligibility = eligibilityCriteria if (eligibility) { for (const [ci, criteria] of eligibility.entries()) { // TODO: this fails to pull the value, returns undefined const field = _.findKey(this.$store.state.application.application, criteria.field) } } } }

¿Qué me estoy perdiendo?

about 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe haber entendido mal lo que hace _.findKey()

Este método es como _.find, excepto que devuelve la clave del predicado del primer elemento y devuelve la verdad en lugar del elemento en sí.

Vea el Ejemplo 2 en el código a continuación.

Si desea recuperar el valor del objeto en una ruta determinada, debe usar _.property() (Ejemplo 2 a continuación)

 const eligibilityCriteria = [ { field: 'loan.amount', operator: '>=', value: 1000 }, { field: 'loan.term', operator: '>=', value: 1 }, ] const application = { loan: { amount: 500, term: 2, amount2: 0, } } // example 1 // outputs "loan" console.log(_.findKey(application, "amount")) // outputs undefined - there is no key in application object that has property chain "loan.amount" console.log(_.findKey(application, "loan.amount")) // outputs undefined - "amount2" key is there but the value is falsy console.log(_.findKey(application, "amount2")) // example 2 for (const [ci, criteria] of eligibilityCriteria.entries()) { console.log(criteria.field, _.property(criteria.field)(application)) }
 <script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>

about 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error