如何使用utils.api.productAttributes.optionChange在 React 功能组件上以及当您无权访问 $form.serialize()
我尝试手动创建这样的 formData,但它不起作用。
const addOption = () => {
const formData = new FormData();
formData.append("action", "add");
formData.append("product_id", "459");
formData.append("optionValue", "12213");
formData.append("attribute", "25331");
console.log(formData);
utils.api.productAttributes.optionChange(
459,
formData,
(err, response) => {
const attributesData = response.data || {};
console.log("err: ", err);
console.log("res: ", response);
// I just copied this from the documentation but where do I get these methods?
this.updateProductAttributes(attributesData);
this.updateView(attributesData);
}
);
};
我收到了这些errors虽然响应状态代码是200,而我的formData只是空的。
最佳答案
文档中没有对此进行解释,但您实际上不需要序列化表单数据,您只需要属性 ID 和值。试试这个:
const addOption = () => {
utils.api.productAttributes.optionChange(
459,
'attribute%5B25331%5D=12213',
(err, response) => {
const attributesData = response.data || {};
console.log("err: ", err);
console.log("res: ", response);
// I just copied this from the documentation but where do I get these methods?
this.updateProductAttributes(attributesData);
this.updateView(attributesData);
}
);
};
关于javascript - 如何使用 BigCommerce utils.api.productAttributes.optionChange,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72907722/