简体   繁体   English

如何使用 Ant Design Vue 禁用 Select 中的特定元素?

[英]How can i disable a specific element in a Select with Ant Design Vue?

I'm trying to disable a specific element of a a-select .我正在尝试禁用a-select的特定元素。 And for that, i have a function " check_function " and i'm returning the string " disabled " when i want to disable an element.为此,我有一个 function “ check_function ”,当我想禁用一个元素时,我返回字符串“ disabled ”。 I have我有

      <a-select @change="onTestChanged" :value="currentTestId" >
        <a-select-option 
          v-for="test in tests" v-bind:key="test.id"
          :value="test.id" 
          :disabled="check_function(test.id) == 'disabled'"
        >
          {{ test.testName }}
        </a-select-option>
      </a-select>

I want to disable an element of my a-select when the function " check_function " is returning " disabled ".当 function“ check_function ”返回“ disabled ”时,我想禁用我的 a-select元素。

async check_function(id) {
  await this.$store.dispatch("fetch_test", id)
  var save = this.$store.getters.get_test()
  if (save.length == 0) {
    console.log("disabled")
    return "disabled"
  }
},

And basically, when i'm checking with console.log , the condition it's working.基本上,当我检查console.log时,它的工作条件。 When i want to disable a element, it's printing " disabled ".当我想禁用一个元素时,它正在打印“ disabled ”。

But my disabled is not working.但我的残疾人不工作。 When i'm cheking my a-select in my front, nothing is happening当我在前面检查我的 a-select 时,什么都没有发生

When i'm doing当我在做

check_function(id) {
  return "disabled"
},

All the elements of my select are disabled.我的 select 的所有元素都被禁用。

So, why it's not working with the first way?那么,为什么它不适用于第一种方式?

Not an answer but some tips to debug不是答案,而是一些调试技巧

Check whether save is null.检查保存是否为null。 This would help ensure at least you're not missing the if check because your "save" variable is undefined or null.这将有助于确保至少您不会错过 if 检查,因为您的“保存”变量未定义或 null。

async check_function(id) {
  await this.$store.dispatch("fetch_test", id)
  var save = this.$store.getters.get_test()
  if (!save || save.length == 0) {
    console.log("disabled")
    return "disabled"
  }
},

Check whether it's returning null before it goes to your if check.检查它是否返回 null,然后再进行 if 检查。 This should by right disable all.这应该正确禁用所有。 If it doesn't then it's a problem如果没有,那就有问题了

async check_function(id) {
  await this.$store.dispatch("fetch_test", id)
  return "disabled"
}

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

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