Get value of found array index

Posted 5 months ago by axtg


This may be a basic Javascript question, but I am trying to achieve the following...

  1. I have a Laravel Model that holds all attributes $attributes = Attribute::get(); that can be linked with properties (many to many; attributes_properties)

  2. I have a Laravel loaded array with objects that hold previously specified properties and with that the value of the property e.g. [{'id' => 1, 'value' => 'first'}, {'id' => 2, 'value' => 'second'}]. Passed as prop (selectedAttributes) to Vue.

The id in the Laravel model (1) equals the id listed in (2)

I am listing all attributes on a page via Vue (<div v-for="(attribute, index) in attributes">

Now I want to prefill the value for those attributes that have been filled before. Which theoretically means...

<div v-for="(attribute, index) in attributes">
    <input :value="[selectedAttributes.includes( ? selectedAttributes.value : '']">

But that obviously doesn't work (because selectedAttributes is missing an index).

Any pointers, as always, are welcome.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.