html - Set v-model to be a key in array (v-model.key="someArray") -


i'm doing filter page , need store filter name , filter value, purpose, have structure that:

data: { attributes: { checkboxes: [], strings: { keys: [], values: [] }, ...

and html (btw i'm using laravel blade that's not relevant here):

... @if ($atribut->type == 'checkbox')    <label class="btn btn-default" for="{{ $atribut->tag }}"> {{ $nom }} <input v-model="attributes.checkboxes" class="badgebox" id="{{ $atribut->tag }}" type="checkbox" value="{{ $atribut->id }}"><span class="badge">&check;</span></label>    <br>    <br> @endif @if ($atribut->type == 'string')   @php $nom = obj_array_find(db::table('literals')->get(), $atribut->nom, 'id')->cat @endphp   <input type="hidden" v-model="attributes.strings.keys" value="{{ $atribut->id }}">   {!! form::text($atribut->tag, null, ['class' => 'form-control', 'placeholder' => $nom, 'v-model' => 'attributes.strings.values']) !!}   <br> @endif ... 

the question is, possible have that:

<input type="hidden" v-model.key="attributes.strings" value="{{ $atribut->id }}"> {!! form::text($atribut->tag, null, ['class' => 'form-control', 'placeholder' => $nom, 'v-model.value' => 'attributes.strings]) !!} 

to answer specific question, v-model bind 1 key value pair, don't need assign key.

the way structured input binding input box bind object value field , you'll see [object object] in input box.

i created jsfiddle shows how bind model. assumed data modeled in list format below.

attributes: [     {checkboxes: [1], strings: { keys: [1], values: ['tomato'] }},     {checkboxes: [2], strings: { keys: [2], values: ['potato'] }} ] 

i offered json object watch data update each of these 2 keys. in debugging trying go.

jsfiddle doesn't have way render laravel blade, here blade version:

<input v-for="attribute in attributes" type="hidden" v-model="attribute.strings.values" value="1"> {!! form::text('bam', null, ['v-for' => 'attribute in attributes', 'class' => 'form-control', 'placeholder' => 'boom',          'v-model' => 'attribute.strings.values']) !!} 

if, mention @ beginning of question, looking create filter (i assume autocomplete type object?), wouldn't way it.

hope helps.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -