gpt4 book ai didi

javascript - 迭代数据脚本中的键

转载 作者:行者123 更新时间:2023-12-03 00:05:08 24 4
gpt4 key购买 nike

我试图弄清楚如何将下拉菜单中的用户输入值与 ID 对象进行比较,其中键与 Vue 中的下拉菜单选项相匹配。

示例:

<template>  
<select v-model="selectMenu">
<option v-for"select in selections">{{ selection }}</option>
</select>
</template>

<script>
export default {
data() {
return {
selectMenu: '',
selections: [ 'one', 'two', 'three' ],
ids: {
one: 'dfs745jfdb',
two: 'adfjdsh3gf5',
three: 'ag23dsgnsj'
}
}
}
}
</script>

我想出了如何以更简单的方式做到这一点。我对 vue 和一般编码非常陌生。我所做的是将选择和 id 合并到一个数组中,如下所示: 解决方案:

<template>  
<select v-model="selectMenu">
<option v-for"selectId in selectIds" v-bing:value="selectId.id">
{{ selectId.text }}
</option>
</select>
</template>

<script>
export default {
data() {
return {
selectMenu: '',
selectIds: [
{ text: 'one', id: 'dfs745jfdb' },
{ text: 'two' id: 'adfjdsh3gf5' },
{ text" 'three' id: 'ag23dsgnsj' }
]
}
}
}
</script>

最佳答案

this.ids[this.selectMenu] 应该为您提供 ids 对象中的对象。

关于javascript - 迭代数据脚本中的键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54993167/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com