Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

314
Vistas
I can't display json with select option (Laravel Vue)

I want to display the value in Options with province_id and province. but in the options it always appears in JSON format. please help me i'm stuck

this my create.js

 changeShippingCountry(country) {
        this.$set(this.form.shipping, 'country', country);

        this.fetchStates(country, (states) => {
            this.$set(this.states, 'shipping', states);
            this.$set(this.form.shipping, 'state', '');
        });
    },

    fetchStates(country, callback) {
        $.ajax({
            method: 'GET',
            url: route('provinces'),
            dataType: "json",
        }).then(callback);
    },

and this billing_detail.blade.php

<input
                        type="text"
                        name="billing[state]"
                        :value="form.billing.state"
                        id="billing-state"
                        class="form-control"
                        v-if="! hasBillingStates"
                        @change="changeBillingState($event.target.value)"
                    >

                    <select
                        name="billing[state]"
                        v-model="form.billing.state"
                        id="billing-state"
                        class="form-control arrow-black"
                        v-else
                    >
                        <option value="">{{ trans('storefront::checkout.please_select') }}</option>

                        <option
                            v-for="(name, code) in states.billing"
                            :value="code"
                            v-text="name"
                        >
                        </option>
                    </select>

this is result in options

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I can't see how your backend data is provided in PHP, but I'm making the assumption here that states.billing is an array of objects, each object with the elements province_id and province in it.

In the vue documentation, you can read that the 2nd arguments you put in between brackets at the front of a v-for loop differ, depending on whether your v-for loops over an array or an object.

If it is an array, the documentation reads:

v-for also supports an optional second argument for the index of the current item.

If it is an object, the documentation reads:

You can also provide a second argument for the property’s name (a.k.a. key)

Considering that you are looping over an array (of objects), you should probably update your v-for loop to something like this:

<option
  v-for="(item, index) in states.billing"
  :value="item.province_id"
  :key="index"
>
  {{ item.province }}
</option>

Note that I'm using the index for the key attribute here. If your province_id is unique, you can also do the following:

<option
  v-for="item in states.billing"
  :value="item.province_id"
  :key="item.province_id"
>
  {{ item.province }}
</option>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda