Unable to create selected buttons in Vue.js

I'm having trouble creating buttons that can select all options when clicking on either size or color. The buttons aren't showing up at all. Can someone help me identify the issue?

I've attempted various solutions but none seem to work. Any insights into what might be going wrong?

    <template>
     <div v-if="iProduct.active == 1">
      <div v-for="value in iProduct.variants[0].option_values" :key="value.id">
        <span v-if="value.option.name == 'color'">All Color</span>
        <span v-else>All Size</span>

         <q-btn
         v-for="(option, index) in getComboOptions(value.option.name, iProduct.variants)"
         :key="index"
         size="md"
         @click="addVariantsByOptionName(option, iProduct.variants)"
        >
          {{option}}
          {{value.option.name}}
        </q-btn>
      </div>
     </div>
    </template>

This is the script part

methods: {
variantSelected(variant) {
      this.$emit('variantSelected', variant);
},
getComboOptions(name, variants) {
      let result = [];
      if (variants == undefined) return result;
      //if (variants < 0) return result;

      for (let variant of variants) {
        for (let optionValue of variant.option_values) {
          if (optionValue.option.name == name) {
            console.log('--- optionValue.value : ' + optionValue.value);
            let dup = 0;
            for (let r of result) if (r == optionValue.value) dup++;
            if (dup == 0) result.push(optionValue.value);
          }
        }
      }
},
addVariantsByOptionName(optionName, variants) {
      console.log('--- variants : ' + variants);
      for (let variant of variants) {
        for (let optionValue of variant.option_values) {
          if (optionName == optionValue.value) {
            this.variantSelected(variant);
          }
        }
      }
 },
}

Thank you!

Answer №1

The mystery has been solved! I discovered the missing piece - return result; was not included in the getComboOptions() function.

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

Retrieving Information from Ajax Call Using Python

I am struggling to figure out how to retrieve data from an Ajax request in my JavaScript code within a Python Flask application. The Ajax request I am working with does not involve jQuery. I have attempted using request.form.get() and request.get_json() i ...

What is the best way to connect click events with ExtJS template elements?

Is there a way to assign a click event to each link tag without directly embedding onclick=.... in the XTemplate code? new Ext.XTemplate( '<ul>', '<tpl for="."><li><a href="#{anchor}">{text}</a></li& ...

Experiencing issues with creating HTML using JavaScript?

I'm a JavaScript novice and struggling to figure out what's wrong with my code. Here is the snippet: var postCount = 0; function generatePost(title, time, text) { var div = document.createElement("div"); div.className = "content"; d ...

Info window in Vue Google Maps

I am working on a Vue app that displays a Google Map using vue2-google-map. However, I am facing an issue with implementing maps.infowindow to my marker because there is a lack of Vue.js reference source. Here is the code for my marker template: <Gmap ...

Oops, it seems like there was an issue with NextJS 13 Error. The createContext functionality can only be used in Client Components. To resolve this, simply add the "use client" directive at the

**Issue: The error states that createContext only works in Client Components and suggests adding the "use client" directive at the top of the file to resolve it. Can you explain why this error is occurring? // layout.tsx import Layout from "./componen ...

Displaying nested JSON data in a user interface using React

I have a complex nested JSON structure that I am using to build a user interface. While I have successfully implemented the first part, I am encountering difficulties with the second part. My Objective The nested JSON displays parent elements and now I a ...

What is the proper way to include jQuery script in HTML document?

I am facing an issue with the banners on my website. When viewed on mobile devices, the SWF banner does not show up. In this situation, I want to display an <img> tag instead, but the jQuery code is not functioning correctly. My template structure l ...

Exploring object manipulation and generating unique identifiers by combining values - a beginner's guide

After analyzing the provided data, my goal is to come up with a method of combining the IDs and returning an array of their corresponding keys. // example data var data = [ { id: 1, key: 'a' }, { id: 1, key: 'b' }, { id: 2, key ...

Using various hues for segmented lines on ChartJS

I am working with a time line chart type and I want to assign colors to each step between two dots based on the values in my dataset object. In my dataset data array, I have added a third item that will determine the color (if < 30 ==> green / >3 ...

Is it possible to mimic a ref attribute with jest/rtl within a functional component?

I'm currently facing an issue with a functional component that includes a helper function. function Component() { imgRef = useRef(null) function helperFunction(node, ref) { if (!ref || !ref.current) return; ...do someth ...

Insert Angular HTML tag into TypeScript

I am currently working on creating my own text editor, but I'm facing an issue. When I apply the bold style, all of the text becomes bold. How can I make it so that only the text I select becomes bold without affecting the rest of the text? Additional ...

"Enhance your website with the dynamic duo of Dropzone

Currently, I am utilizing dropzone.js and loading it through ajax. I have assigned my menu ID as "#menu". The uploaded file should display in "#div1". Unfortunately, the callback function is not functioning properly. In an attempt to troubleshoot, I repl ...

v-select/Vue: Can I input a value that is not in the dropdown list?

I'm looking for a solution to include a new value in v-select that is not already in the list. I want the newly entered value to be selected as an option. Below is my existing code: <v-select ref="systemSelect" v-model="reservation.system" ...

What's the alternative now that Observable `of` is no longer supported?

I have a situation where I possess an access token, and if it is present, then I will return it as an observable of type string: if (this.accessToken){ return of(this.accessToken); } However, I recently realized that the of method has been deprecated w ...

Flow bar for micro-tasks

In my current project, I am faced with the task of organizing a series of 4 mini tasks and displaying to the end user which specific mini task they are currently on. To accomplish this, I have been utilizing image tags for each task. <img>1</img ...

preventing the page from scrolling whenever I update my Angular view

Whenever I update a part of my model that is connected to my view, my page automatically scrolls. I suspect that the page scrolling is triggered by the view updates. How can I stop this from happening? For instance, here is an example involving a dropdown ...

What is the best method for exchanging data between two Vue instances?

index.html <script defer src='main.js'></script> <script defer src='extension.js'></script> <div id='main-app'></div> <div id='extension'></div> main.js const store ...

How can I change an element using jQuery's getElementById method?

My current setup involves using a web page as a server and an Arduino as a client. Whenever a specific mode is active, the Arduino sends the following code: <LED>on</LED> The server then adjusts its status accordingly based on this input. I ...

What is the correct way to transform an Error object to a string in Node.js?

Every time I input a duplicate entry in mysql, this error pops up. { [Error: ER_DUP_ENTRY: Duplicate entry '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="35465458455950755258545c591b-565a58">[email protected]< ...

Transferring properties from the main layout to a specific component

Recently delving into the world of Vue, I find myself in need of passing props from a layout to a global component. Although my search skills may not be up to par, I have been tinkering with a default layout setup as follows: layouts/default.vue <templ ...