Issue with changing the first select box due to nesting restrictions

In my Vue.js component, I am working on a logic involving two nested select boxes. I load data from a JSON file and pass it to an array within the component. The JSON file contains the logic for the two select boxes. For example, under "Business Development" in the first box, I want to load options like "Financial Proposal" and "Master Licence and Service Agreement":

{
    "Business Development": [
        {
            "text": "Financial Proposal",
            "key": 1
        },
        {
            "text": "Master Licence and Service Agreement",
            "key": 2
        },
        {
            "text": "Non-Disclosure Agreement",
            "key": 3
        },
        {
            "text": "Relatório de Missão",
            "key": 4
        }
    ],
    "Configuration Management": [
        {
            "text": "Configuration Management Plan",
            "key": 1
        },
        {
            "text": "Configuration Management Plan For Implementation Projects",
            "key": 2
        }

I have managed to achieve this functionality. However, when I change the selection in the first select box, the second one becomes empty at position 1, as shown here:

https://i.sstatic.net/W7aCY.png

Here is the relevant code snippet:

<template>
  <div class="row margin-above2 box">
    <h3 class="text-center">Template</h3>
    <img width="70px" height="70px" class="img img-responsive" src="static/img/word.png">
      <form class="box-body form-horizontal">
        <div class="form-group">
          <div class="col-sm-12">
            <select class="form-control" v-model="docData.documentType">
              <option v-for="(item,index) in documentNested">
                {{ index }}
              </option>
            </select>
          </div>
        </div>
        <div class="form-group">
          <div class="col-sm-12">
            <select class="form-control" v-model="docData.documentSelection">
              <option v-for="(item,index) in documentNested[docData.documentType]">{{item.text}}</option>
            </select>
          </div>
        </div>
      </form>
    </div>
</template>


<script>
import data from '../../interfaceData/documentType.json'
import permissions from '../../interfaceData/permissions.json'

export default {
  name: 'app',
  data () {
    return {
      checked: false,
      documentNested: data,
      permissions: permissions,
      listItems: [],
      documentData: []
    }
  },

Your assistance would be highly appreciated! :)

Answer №1

Ensure to include the value bind for each option, indicating the value that each option represents.

<option v-for="(item,index) in documentNested[docData.documentType]" :value="item">{{item.text}}</option>

To automatically select an option when the first select changes, a watcher can be used.

watch: {
    'docData.documentType'(val) {
        this.docData.documentSelection = this.documentNested[val][0];
    }
}

A simulation of your component can be found here, which may offer some assistance:

https://jsfiddle.net/9uke1596/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Displaying information from an array using AngularJS

I'm struggling to display data from an array and I could use some help. Here's a snippet from my service.js file: this.fetchData = function() { var myArray = $resource('url', {method: 'get', isArray: true}); myArray ...

RxJS operators should not be confused with regular functions

I am encountering an issue when attempting to utilize rxjs in vue with vue-rx and rxjs together. [Vue warn]: Error in created hook: "TypeError: messageObservable.fromEvent(...).map(...).debounceTime is not a function" After reviewing the documentation, I ...

What Causes the "Not a String or Buffer Type" Unhandled Exception?

I've encountered an error that seems to be originating from the following line of code, even though I believe I am following the example correctly (viewable at https://www.npmjs.org/package/aws-sign). Any help or hints would be greatly appreciated. v ...

Is it not odd that there are two '=>' symbols in an arrow function when there is typically only one? What could this possibly signify?

function updateStateValue(name) { return (event) => { setState({ ...state, [name]: event.target.checked }); }; } To view the full code example, visit CodeSandbox. ...

The functionality of the disabler button is not fully operational on tablet devices

-I have a button: -I would like to use JavaScript to disable it: document.getElementById("input-datestart").disabled = true; -CSS: input:disabled { background-color: #fff!important; color: #000; } Text color [color: #000;] While it works on ...

Is it possible to efficiently utilize Map/Set in TypeScript/JavaScript when working with objects?

I'm currently transitioning from Java to TypeScript and I've encountered an issue with working with objects in hashmaps and hashsets. In Java, I would simply override the hashCode method to easily manipulate these data structures. Is there a simi ...

Sending JSON data parsed by oboe.js to the http response object in a Node.js server

Using Oboe.js for JSON parsing from a Node readStream with the aim of sending it back to the requesting client in a memory-efficient manner. I'm exploring the possibility of piping data from Oboe's node or path events to a Node.js HTTP response o ...

Jquery failing to trigger click() on a div with an id

Within my erb file, there exists a script that looks like the following: function checkJquery() { if(window.jQuery) { jQuery(document).ready(function() { alert('onready'); $('div#habla_topbar_div').click(function( ...

404 Response Generated by Express Routes

Exploring the MEAN stack has been a great way for me to expand my knowledge of node and express. Currently, I am working on creating a simple link between two static pages within the app. My routes are set up as follows: //Home route var index = require( ...

Calculating the rotation angle of a spinning cylinder in Three.js animations

I'm struggling with this Math problem and my skills are failing me. To see my progress so far, you can view the working example here. After extracting the y and z positions from the rotating cylinder, I've managed to pause the animation when the ...

Retrieving the content of a dynamic template with Angular-UI-Router

Currently, I am in the process of developing an angular application utilizing angular-ui-router. The backend of the application consists of a REST api that provides a form URL based on a specific ticket id. My aim is to dynamically set the template in app. ...

Is it permissible to have circular references between JSON Schemas that are stored in separate files?

I am currently working with two JSON schemas that reference each other: schema.task.json and schema.dependency.json: //file: schema.task.json { "$schema": "http://json-schema.org/draft-04/schema", "type": "object", "properties": { "Dep ...

Struggling to pass a function argument as a string for use within the function

Although the title may seem unclear, I will clarify. I have a collection of images on the left side and I have implemented an onclick function on each one to display the image and some information on the right side. It's like having thumbnails on the ...

Assign the input value to the success callback for the ajax request

I am facing an issue with setting the data returned from a success callback in an AJAX request as an input value. It seems like this problem is arising because I am using the AJAX request within an event function (.on). For updating the specific input, I b ...

"Troubleshooting why the jQuery Click Function is malfunctioning specifically in

Can someone help me troubleshoot this animate out script? It works fine on chrome, but not on Firefox and I can't seem to figure out why. Any suggestions? The script is designed to animate certain elements when a specific link is clicked. <scrip ...

Generating a package.json file that includes a comprehensive list of all development dependencies

My Inquiry I've been pondering whether it's possible to include all the necessary devDependencies within the package.json file generated by running npm init in the Terminal for Gulp projects. Can these dependencies be pre-listed in the file inst ...

What is the best way to combine two sections in html/css/bootstrap?

I've been trying to create a simple webpage with a navigation bar and a section below it, but I keep running into an issue where there's unwanted white space between the nav bar and the next section in blue. Is there a way to eliminate this gap a ...

What is the best way to implement Breadcrum in AngularJS?

I'm looking to integrate breadcrumbs into my application using AngularJS. I've already set up the router and header file, but I'm unsure of how to proceed with implementing breadcrumbs in AngularJS. INDEX <div class="container mainI ...

Issue: It is necessary to utilize the `@babel/plugin-transform-runtime` plugin if you have set `babelHelpers` to "runtime" when using npm link

My situation involves having two interconnected React libraries: project-ui and propert-utils. project-ui relies on propert-utils, and the latter is installed within the former. "devDependencies": { "@company/project-utils": "gi ...

Over-extended Affix in Bootstrap 3.1.0

I'm currently using Bootstrap 3.1.0. The issue I've encountered is that when the "affix" becomes too long for the viewport, it ends up getting cut off and doesn't display the bottom items. Is there a way to make Bootstrap's affix featu ...