简体   繁体   English

Vue.js / 创建所有选定的按钮不起作用

[英]Vue.js / Creating all selected buttons does not work

I would like to create buttons that can select all options when clicking either size or color.我想创建可以在单击大小或颜色时选择所有选项的按钮。 However, even the buttons don't show up.但是,即使是按钮也不显示。 What is the problem?问题是什么?

I tried many things, but did not work.我尝试了很多东西,但没有奏效。 Can you tell me the issue?你能告诉我问题吗?

    <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!谢谢!

I found out the reason why.我找到了原因。 I did not put return result;我没有放return result; in getComboOptions() !!getComboOptions() !!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM