Vue-Sweetalert2的preConfirm是否允许您传递包含多个字符串的对象?

时间:2019-07-03 08:28:33

标签: vue.js vue-sweetalert2

当前,我正在练习网页上,并创建一个“创建”按钮,该按钮会触发一个弹出窗口,您可以在其中填写您的个​​人数据,例如姓名,街道地址等(如附件所示)。

popup

我想将用户地址存储为一个由多个字符串组成的对象,而不是单个字符串,例如

ModelAdmin

但是这里有一个问题。尽管我创建了弹出窗口,并且成功地通过了用户输入,但在传递数据时,地址并未存储为“地址”对象。相反,它们是5个单独的字符串,如下图所示。

not an address object

请注意,输出中没有花括号,而我希望输出如下所示

YourModelAdmin

这是我要达到预期目标的样子,因为这种方式将地址存储为由5个字符串组成的“地址”对象。

检查完我自己的代码(如下所示)后,

autocomplete_fields = ['something']

我怀疑问题出在autocomplete_view方法的ModelAdmin上,因为它通过Something提取了10个单独的值,并将它们存储到"address": { "street": "string", "city": "string", "country": "string", "region": "string", "zipCode": "string" } 中。

我想做的事情类似于以下内容,因为我想将“地址”作为由5个字符串组成的对象进行传递。

Test result of createCustomer: [ "JS1", "fi_FI", "123ABC", {"stackoverflow st 12", "San Francisco", "USA", "California", "12345"}, "Shinichi", "Takagi" ]

但是问题是这不是正确的语法,并且会导致编译错误。

有什么办法可以让<template> <div style="padding: 2em;"> <v-flex xs12 sm6 md3> <v-btn class="create-button" color="yellow" @click="alertDisplay">Create</v-btn> </v-flex> <br /> <p v-if="createdCustomer">Test result of createCustomer: {{ createdCustomer }}</p> </div> </template> <script> export default { data() { return { createdCustomer: { customerNumber: null, locale: null, regNo: null, address: { street: null, city: null, country: null, region: null, zipCode: null }, firstName: null, lastName: null } } }, methods: { async alertDisplay() { const {value: formValues} = await this.$swal.fire({ title: 'Create private customer', html: '<input id="swal-input1" class="swal2-input" placeholder="Customer Number">' + '<select id="swal-input2" class="swal2-input"> <option value="fi_FI">fi_FI</option> <option value="sv_SE">sv_SE</option> </select>' + '<input id="swal-input3" class="swal2-input" placeholder="regNo">' + '<input v-model="createdCustomer.address.street" id="swal-input4" class="swal2-input" placeholder="Address (street)">' + '<input v-model="createdCustomer.address.city" id="swal-input5" class="swal2-input" placeholder="Address (city)">' + '<input v-model="createdCustomer.address.country" id="swal-input6" class="swal2-input" placeholder="Address (country)">' + '<input v-model="createdCustomer.address.region" id="swal-input7" class="swal2-input" placeholder="Address (region)">' + '<input v-model="createdCustomer.address.zipCode" id="swal-input8" class="swal2-input" placeholder="Address (zipCode)">' + '<input id="swal-input9" class="swal2-input" placeholder="First Name">' + '<input id="swal-input10" class="swal2-input" placeholder="Last Name">' , focusConfirm: false, preConfirm: () => { return [ document.getElementById('swal-input1').value, document.getElementById('swal-input2').value, document.getElementById('swal-input3').value, document.getElementById('swal-input4').value, document.getElementById('swal-input5').value, document.getElementById('swal-input6').value, document.getElementById('swal-input7').value, document.getElementById('swal-input8').value, document.getElementById('swal-input9').value, document.getElementById('swal-input10').value ] } }) if (formValues) { this.createdCustomer = formValues; console.log('the content of this.createdCustomer'); console.log(this.createdCustomer); console.log('the content of this.createdCustomer.address'); console.log(this.createdCustomer.address); } } }, } </script> 传递我所描述的“地址”对象?还是应该首先重新考虑使用preConfirm并找到其他方法?

0 个答案:

没有答案