0

Estou com problema para selecionar os options de um select com os dados de inicio e fim dentro das chaves dinâmicas do seguinte json multidimensional:

 rowsels: {"dias":{"seg":{"inicio":"08:00","fim":"18:00"},"ter":{"inicio":"09:00","fim":"15:00"},"qua":{"inicio":"10:00","fim":"19:00"},"qui":{"inicio":"15:00","fim":"17:00"},"sex":{"inicio":"08:00","fim":"18:00"},"sab":{"inicio":"24horas","fim":"00:00"},"dom":{"inicio":"fechado","fim":"00:00"}},"obs":"N\u00e3o atendemos em finais de semanas e feriados. Entramos em f\u00e9rias em dezembro at\u00e9 fevereiro."};

Eu precisava fazer algo mais ou menos assim:

v-model="rowsels.dias.{{ index }}.inicio"
v-model="rowsels.dias.{{ index }}.fim"

Ja tentei de várias outras formas e nada deu certo até agora.

Alguém pode me ajudar? ♥

Segue o código completo do que estou tentando fazer:

new Vue({
        el: "#horariosvue",
        data: {
           rowsels: {"dias":{"seg":{"inicio":"08:00","fim":"18:00"},"ter":{"inicio":"08:00","fim":"18:00"},"qua":{"inicio":"08:00","fim":"18:00"},"qui":{"inicio":"08:00","fim":"18:00"},"sex":{"inicio":"08:00","fim":"18:00"},"sab":{"inicio":"24horas","fim":"00:00"},"dom":{"inicio":"fechado","fim":"00:00"}},"obs":"N\u00e3o atendemos em finais de semanas e feriados. Entramos em f\u00e9rias em dezembro at\u00e9 fevereiro."},
           rows: {"seg":"Segunda","ter":"Ter\u00e7a","qua":"Quarta","qui":"Quinta","sex":"Sexta","sab":"S\u00e1bado","dom":"Domingo"}
        }
    });
<script src="https://cdn.jsdelivr.net/npm/vue"></script>

<div id="horariosvue">
	<div class="form-group" v-for="(row, index) in rows">
		<div class="col-md-2">{{ row }}</div>
		<div class="col-md-5">
			<select v-bind:name="'horario[dias]['+index+'][inicio]'" 
                v-model="rowsels.dias.{{ index }}.inicio">

				<option value="fechado">Fechado</option>
				<option value="24horas">24 horas</option>
				<option value="00:00">00:00</option>
				<option value="00:30">00:30</option>
				<option value="01:00">01:00</option>
				<option value="01:30">01:30</option>
				<option value="02:00">02:00</option>
				<option value="02:30">02:30</option>
				<option value="03:00">03:00</option>
				<option value="03:30">03:30</option>
				<option value="04:00">04:00</option>
				<option value="04:30">04:30</option>
				<option value="05:00">05:00</option>
				<option value="05:30">05:30</option>
				<option value="06:00">06:00</option>
				<option value="06:30">06:30</option>
				<option value="07:00">07:00</option>
				<option value="07:30">07:30</option>
				<option value="08:00">08:00</option>
				<option value="08:30">08:30</option>
				<option value="09:00">09:00</option>
				<option value="09:30">09:30</option>
				<option value="10:00">10:00</option>
				<option value="10:30">10:30</option>
				<option value="11:00">11:00</option>
				<option value="11:30">11:30</option>
				<option value="12:00">12:00</option>
				<option value="12:30">12:30</option>
				<option value="13:00">13:00</option>
				<option value="13:30">13:30</option>
				<option value="14:00">14:00</option>
				<option value="14:30">14:30</option>
				<option value="15:00">15:00</option>
				<option value="15:30">15:30</option>
				<option value="16:00">16:00</option>
				<option value="16:30">16:30</option>
				<option value="17:00">17:00</option>
				<option value="17:30">17:30</option>
				<option value="18:00">18:00</option>
				<option value="18:30">18:30</option>
				<option value="19:00">19:00</option>
				<option value="19:30">19:30</option>
				<option value="20:00">20:00</option>
				<option value="20:30">20:30</option>
				<option value="21:00">21:00</option>
				<option value="21:30">21:30</option>
				<option value="22:00">22:00</option>
				<option value="22:30">22:30</option>
				<option value="23:00">23:00</option>
				<option value="23:30">23:30</option>
			</select>  
		</div>
		<div class="col-md-5">
			<select v-bind:name="'horario[dias]['+index+'][fim]'"
             v-model="rowsels.dias.{{ index }}.fim">

				<option value="00:00">00:00</option>
				<option value="00:30">00:30</option>
				<option value="01:00">01:00</option>
				<option value="01:30">01:30</option>
				<option value="02:00">02:00</option>
				<option value="02:30">02:30</option>
				<option value="03:00">03:00</option>
				<option value="03:30">03:30</option>
				<option value="04:00">04:00</option>
				<option value="04:30">04:30</option>
				<option value="05:00">05:00</option>
				<option value="05:30">05:30</option>
				<option value="06:00">06:00</option>
				<option value="06:30">06:30</option>
				<option value="07:00">07:00</option>
				<option value="07:30">07:30</option>
				<option value="08:00">08:00</option>
				<option value="08:30">08:30</option>
				<option value="09:00">09:00</option>
				<option value="09:30">09:30</option>
				<option value="10:00">10:00</option>
				<option value="10:30">10:30</option>
				<option value="11:00">11:00</option>
				<option value="11:30">11:30</option>
				<option value="12:00">12:00</option>
				<option value="12:30">12:30</option>
				<option value="13:00">13:00</option>
				<option value="13:30">13:30</option>
				<option value="14:00">14:00</option>
				<option value="14:30">14:30</option>
				<option value="15:00">15:00</option>
				<option value="15:30">15:30</option>
				<option value="16:00">16:00</option>
				<option value="16:30">16:30</option>
				<option value="17:00">17:00</option>
				<option value="17:30">17:30</option>
				<option value="18:00">18:00</option>
				<option value="18:30">18:30</option>
				<option value="19:00">19:00</option>
				<option value="19:30">19:30</option>
				<option value="20:00">20:00</option>
				<option value="20:30">20:30</option>
				<option value="21:00">21:00</option>
				<option value="21:30">21:30</option>
				<option value="22:00">22:00</option>
				<option value="22:30">22:30</option>
				<option value="23:00">23:00</option>
				<option value="23:30">23:30</option>
			</select> 
		</div>
	</div>
</div>

1 Resposta 1

0

Fiz a mesma pergunta no SO em inglês e tive a seguinte resposta:

Use [] instead of {{}}; mustache ({{}}) is used for text interpolation, and it cannot be used inside HTML attributes, for which you need to use javascript expressions:

v-model="rowsels.days[index].start"
v-model="rowsels.days[index].end"

Eu ja tinha tentado de uma forma parecida:

v-model="rowsels.dias.[index].inicio"

Mas o meu erro foi usar o ponto antes do colchete (dias.[index]). O correto deve ser: dias[index] ficando assim:

v-model="rowsels.dias[index].inicio"
v-model="rowsels.dias[index].fim"

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .