【发布时间】:2019-09-15 00:57:39
【问题描述】:
我的客户对象有一系列与之关联的信用卡,如下所示:
{
"_id":"5d63e3a32f093f2b5e41ef96",
"firstName": <firstName>,
"lastName": <lastName>,
"email": <email>,
"createdAt":"2019-08-26T13:50:27.409Z",
"modifiedAt":"2019-09-14T20:10:00.257Z",
"paymentMethods":[{
"name": <name>,
"last4": <last4>,
"expirationDate": <expDate>,
"isDefault":false,
"token": <token>
}, {
"name": <name>,
"last4": <last4>,
"expirationDate": <expDate>,
"isDefault":false,
"token": <token>
}, {
"name": <name>,
"last4": <last4>,
"expirationDate": <expDate>,
"isDefault":false,
"token": <token>
}
}
我想在formik中设置初始值。像这样:
const INITIAL_VALUES = {
firstName: customer.firstName,
lastName: customer.lastName,
email: customer.email,
phoneNumber: customer.phone,
paymentMethods: ???????
};
我希望能够编辑付款方式信息。我可以绘制表单,以便所有字段都出现正确的次数,但是如何使用 formik 设置初始值?
谢谢!
【问题讨论】:
-
有一个
initialValues属性传递给 formik。您可能想阅读文档 -
您能否说明到目前为止您所做的哪些工作在您需要帮助的地方不起作用?
-
@sagar.acharya 我知道
initialValues道具。我的问题是当可能有 0 到多个 paymentMethods 时如何指定数组值。 -
@Rikin 我已经在
INITIAL_VALUES对象中尝试了明显的paymentMethods: customer.paymentMethods,但这没有任何作用。 -
找到解决方案了吗?