Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

208
Visualizações
When adjusting the page with the drop-down list, how do I force the page to update with the adjusted value?

I'm making a page for posts that can be viewed by newest or most likes.

I manage this with drop-down lists and arrays.

And whenever the dropdown list is clicked, I have to force update this to match its value.

async selectPosts ({...} = {}, forceUpdate = false) {
        let goodOrderByDir = 'desc'
        let dateOrderByDir = 'desc'
        const db = getFirestore()
        let constraints = [ //This array determines the viewing order.
            orderBy('date', dateOrderByDir), orderBy('good', goodOrderByDir)]

        var hw = document.getElementById('dropDowmListID') //It is linked to a drop-down list.
        hw.addEventListener('change', function() {
            if (hw.value == 1) { //newest
                constraints = [
                    orderBy('date', dateOrderByDir), orderBy('good', goodOrderByDir)]
            }
            if (hw.value == 2) { //most likes
                constraints = [
                    orderBy('good', goodOrderByDir), orderBy('date', dateOrderByDir)]
            }
        })
        if (forceUpdate) {
            this._lastSelectPostsOptions = {}
        }

        constraints.push(limit(pageSize))
        const queryRef = query(collection(db, 'posts'), ...constraints)
        return Promise.all((await getDocs(queryRef)).docs.map(async item => {
            this._lastSelectPostsDoc = item
            const data = item.data()
            return {
                ...data
            }
        }))
    }

Here's the code from where I'm calling it:

searchPosts (isInfinite = false, country = '대한민국', city = '서울특별시', state = '중구', street = '정동', forceUpdate = true) {
      this.firestoreDao.selectPosts({
          lat: 37.566227,
          lot: 126.977966,
          distance: 1,
          sortBy: 'best',
          pageSize: 8,
          includeMine: false,
          country,
          city,
          state,
          street,
          uid: Vue.prototype.$firebaseAuth ? Vue.prototype.$firebaseAuth.getCurrentUserUid() : ''
      }, forceUpdate)
}

When doing a forced update, the default value is false in the current code.

async selectPosts ({...} = {}, forceUpdate = false)

So when I change the dropdown list I was told it must be true to get the next value.

So I changed the code like this

async selectPosts ({...} = {}, forceUpdate = true)

But I couldn't get the value I wanted...

How can I force an update to apply the changed array values?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda