如何对对象数组中的特定属性进行Object.assign()

时间:2018-06-21 06:11:21

标签: javascript vue.js vuejs2

****我在带有vuetify组件的vuejs中使用JSON创建了一个表单。无论我填写的形式字段存储在Firebase中。提交表格后,它将生成数据表。如果要编辑一行,则需要打开表单并在表单字段中获取数据。****

这是我的数据数组:

fields: [{
            type_one: "text",
            label_one: "First Name",
            model_one: "",
            required_one: true,
            rules_one: [
                v => !!v || 'First name is required',
            ],
            type_two: "text",
            label_two: "Last Name",
            model_two: "",
            required_two: true,
            rules_two: [
                v => !!v || 'Last name is required',
            ],
        }, {
            type_one: "text",
            label_one: "Login Name",
            required_one: true,
            model_one: '',
            rules_one: [
                v => !!v || 'Login name is required',
            ],
            type_two: "select",
            label_two: "Customer Name",
            model_two: "",
            required_two: true,
            values: ["Customer 1", "Customer 2"],
            rules_two: [
                v => !!v || 'Customer name is required',
            ],
        }, {
            type_one: "text",
            label_one: "Phone",
            required_one: false,
            model_one: '',
            type_two: "text",
            label_two: "E-mail",
            model_two: "",
            required_two: true,
            rules_two: [
                v => !!v || 'E-mail is required',
                v => /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/.test(v) || 'E-mail must be valid'
            ],
        }, {
            type_one: "password",
            label_one: "Password",
            required_one: true,
            model_one: '',
            rules_one: [
                v => !!v || 'Please enter the password',
            ],
            e1: true,
            type_two: "password",
            label_two: "Confirm Password",
            model_two: "",
            required_two: true,
            rules_two: [
                v => !!v || 'Please confirm the password',
            ],
        }, {
            type_one: "date",
            label_one: "Start Date",
            required_one: true,
            model_one: null,
            menu_one: false,
            rules_one: [
                v => !!v || 'Start Date is required',
            ],
            type_two: "date",
            label_two: "End Date",
            model_two: null,
            required_two: false,
            menu_two: false,
        }, {
            type_one: "text",
            label_one: "Login Expiry(In Days)",
            required_one: false,
            model_one: '',
            type_two: "checkbox",
            label_two: "Is Approval User",
            model_two: '',
            required_two: false,
        }, {
            type_one: "select",
            label_one: "Language",
            values: ["English", "French", "Italic"],
            required_one: false,
            model_one: '',
            type_two: "switch",
            label_two: "Grantee Allowed",
            model_two: '',
            required_two: true,
        }, {
            type_one: "description",
            label_one: "Description",
            required_one: false,
            model_one: ''
        }]

我正在尝试将从api获得的新项目仅分配给上述数组中的 model_one model_two ,例如 this.fields = Object.assign({} ,项目)。 如何实现呢?请帮忙。

这是我来自API的数据

item: [
{
firstName: '',
            lastName: '',
            loginName: '',
            customerName: '',
            phone: '',
            email: '',
            password: '',
            confirmPassword: '',
            startDate: '',
            endDate: '',
            loginExpiry: '',
            approval: '',
            lang: '',
            grantee: '',
            description: ''
}
]

请帮助。谢谢。

0 个答案:

没有答案