在Quasar Select下,以编程方式设置数值。

huangapple go评论67阅读模式
英文:

Programmatically set value in Quasar Select Drop Down

问题

我正在使用Quasar并且有以下代码:

<q-select
    圆角
    勾边
    底部插槽
    堆叠标签
    :紧凑="dense"
    v-model="sexSelected"
    :选项="sexOptions"
    选项值="value"
    标签="性别"
    类="mystyle"
    映射选项
  />

我的sexOptions是:

sexOptions:[ {
            标签: '两性',
            值: '0'
          },
          {
            标签: '男性',
            值: '1'
          },
          {
            标签: '女性',
            值: '2'
          }],

根据用户在不同的选择中选择的值,我需要编程选择男性或女性。

我尝试过:

this.sexSelected.value = "2"

this.sexSelected = "女性"

this.sexSelected = [{标签: '女性', 值: '2' }]
英文:

I'm using Quasar and have the following code:

<q-select
    rounded
    outlined
    bottom-slots
    stack-label
    :dense="dense"
    v-model="sexSelected"
    :options="sexOptions"
    option-value="value"
    label="Sex"
    class="mystyle"
    map-options
  />

My sexOption is:

 sexOptions:[ {
            label: 'Both Sexes',
            value: '0'
          },
          {
            label: 'Male',
            value: '1'
          },
          {
            label: 'Female',
            value: '2'
          }],

Based upon the value an end users selects in a different select I need to select programmatically either Male or Female.

I have tried:

 this.sexSelected.value = "2" 

 this.sexSelected = "Female'

 this.sexSelected = [{label: 'Female', value: '2' }]

答案1

得分: 1

以下是翻译好的部分:

"在尝试了各种不同的组合后,这对于显示和数值都有效

this.sexSelected = ({
label: 'Female',
value: '2'
})"

英文:

After a bunch of different combinations this worked for both the display and the value

this.sexSelected = ({
        label: 'Female',
        value: '2'
      })

答案2

得分: 0

当使用单选/下拉框时,您应始终牢记,幕后只使用值,而不使用标签/名称(用户所见的内容),因此基本上尝试每种方法来设置仅值,而不是标签。

this.sexSelected.value = "2";
this.sexSelected.value = 2;

this.sexSelected = "2";
this.sexSelected = 2;

其中一个应该有效。

英文:

When working with single selects/dropdowns, you should always keep in mind that behind the scene only the value is used and not the label/name (what the user sees), so basically try each of the ways to set only the value, not the label

this.sexSelected.value = "2";
this.sexSelected.value = 2;

this.sexSelected = "2";
this.sexSelected = 2;

one of these should work

huangapple
  • 本文由 发表于 2023年2月23日 23:39:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75547055.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定