【发布时间】:2021-11-13 19:37:43
【问题描述】:
我正在使用 nuxt、vuetify 和 firebase(用于数据库的 cloud firestore)来构建承包商的数据库应用程序。承包商在填写表格时将有多种工作范围 (SOW) 和专业可供选择。
对于 1 个工作范围,会有多种专业选择。因此,每当用户在第一个选择选项上选择 SOW 时,在与该特定 SOW 相关的第二个选择选项上将只有有限数量的专业化可供选择。选择专业后,第三个选择选项将自动显示分配给该专业的代码。 SOW 和专业的所有数据均来自 firestore 数据库。
对于所有 3 个选项,我可以从 firestore 加载数据。只是它没有按照我想要的方式进行动态下拉。
我已经提到了https://jsfiddle.net/mani04/Lgxrcc5p/,但无法真正找到解决方案。有没有办法做到这一点?
此处 3 个选择选项的图片:After select scope, nothing happen on the 2nd select
谢谢!
这是我使用 vuetify v-select 的模板代码
<v-col cols="12" sm="6" md="5">
<v-select
:items="scope"
item-text="scope"
v-model="editedItem.scope"
label="Scope"
@click="listofscope"
></v-select>
</v-col>
<v-col cols="12" sm="6" md="5">
<v-select
:items="special"
item-text="specialization"
v-model="editedItem.specialization"
:disabled="listofspecialization.length == 0"
label="Specialization"
@click="listofspecialization"
></v-select>
</v-col>
<v-col cols="12" sm="6" md="5">
<v-select
:items="special"
item-text="code"
v-model="editedItem.code"
:disabled="listofspecialization.length == 0"
label="Code"
@click="listofspecialization"
></v-select>
</v-col>
这是我的脚本部分
data: () => ({
// ..my other codes
scope: [],
editedIndex: -1,
editedItem: {
scope: '',
},
defaultItem: {
scope: '',
},
special: [],
editedIndex: -1,
editedItem: {
specialization: '',
code: '',
},
defaultItem: {
specialization: '',
code: '',
},
)}
listofscope() {
this.scope = []
db
.collection('Scope of Works')
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
// doc.data() is never undefined for query doc snapshots
this.scope.push({ ...doc.data(), id: doc.id })
})
if (this.listofscope.length > 0) {
this.listofspecialization = [this.scope]
}
console.log(this.scope)
})
},
listofspecialization() {
this.special = []
db
.collectionGroup("Specialization")
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
// doc.data() is never undefined for query doc snapshots
this.special.push({ ...doc.data(), id: doc.id })
})
if (this.listofspecialization.length > 0) {
this.code = [this.scope][this.specialization]
}
console.log(this.special)
})
【问题讨论】:
-
您是否使用观察者来观察变化。因为正如您的代码所说,您使用了
@click,它只收听v-select的点击。它不听变化。尝试改用@change。 -
嗨玛尼,很抱歉回复晚了。使用观察者解决了这个问题。感谢您的建议:))
标签: javascript vue.js google-cloud-firestore nuxt.js vuetify.js