Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

184
Views
How to write condition in JavaScript ternary

I have a select and options in my form but i would like to prepopulate the select with old selected data but i can't seem to get it to work.

Here is my code

<select name="holding_id" v-model="service.holding_id">
              <option value="">Select a holding group</option>
              <option v-for="holding in holdings" v-bind:key="holding.id" v-bind:value="holding.id">
                             {{ holding.holding_name }}
              </option>
  </select>

I am thinking using javascript ternary would make sense

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can try like following snippet:

new Vue ({
  el: "#demo",
  data() {
    return {
      holdings: [{id: 1, holding_name: 'aaa'}, {id: 2, holding_name: 'bbb'}, {id: 3, holding_name: 'ccc'}],
      service: {holding_id: 2}
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="demo">
  <select name="holding_id" v-model="service.holding_id || ''">
    <option value="" disabled>Select a holding group</option>
    <option v-for="holding in holdings" v-bind:key="holding.id" v-bind:value="holding.id">
                   {{ holding.holding_name }}
    </option>
  </select>
</div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!