S
S
sertu2021-10-02 09:12:19
Vue.js
sertu, 2021-10-02 09:12:19

How to get the value in such an array?

Good afternoon, we have such an approximate json array

[
  {
    "fieldTypes": {
      "salary": "20000",
      "vacancyName": "Курьер",
      "geo": "РФ",
      "typeOfWork": "офис"
    },
    "commonFields": {
      "min_age": "18"
    }
  },
  {
    "fieldTypes": {
      "salary": "40000",
      "vacancyName": "Сборщик",
      "geo": "РФ",
      "typeOfWork": "офис"
    },
    "commonFields": {
      "min_age": "18"
    }

  }
]

I want to do a little filtering according to the example https://codepen.io/thaekeh/pen/PoGJRKQ
all the same according to the example, but at this moment there is a plug and an error

let tempInfo = this.info.fieldTypes
computed:{
            filteredOffer(){
                let tempInfo = this.info.fieldTypes

                // Process search input
                if (this.searchVacancyName != '' && this.searchVacancyName) {
                    tempInfo = tempInfo.filter((item) => {
                        return item.vacancyName
                            .toUpperCase()
                            .includes(this.searchVacancyName.toUpperCase())
                    })
                }
            }
        }

Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2021-10-02
@sertu

It is necessary to return an array of all containing the search phrase?

computed: {
  filteredOffer() {
    const search = this.searchVacancyName.toUpperCase();
    if (0 === search.length) return this.info;

    return this.info
      .filter((item) => item.fieldTypes.vacancyName.toUpperCase().includes(search));
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question