javascript - 通过 Symfony API 使用数组发布 JSON 对象
问题描述
我正在尝试将如下 JSON 对象发布到使用 Symfony 开发的后端应用程序(使用 API 平台,前端应用程序和 VueJS):
{
"weight": "10",
"category": ["/api/categories/2", "/api/categories/79"]
}
这是我为我的 HTML 表单(在 VueJS 模板中)尝试的内容:
<form action="/api/data" method="post" axiosMethod="post">
<input type="text" name="weight"> <!-- value=1 -->
<input type="text" name="category[1]"> <!-- value="/api/categories/2" -->
<input type="text" name="category[1]"> <!-- value="/api/categories/79" -->
</form>
这是此表单实际发送的 JSON 文件,这不是我想要的:
{
"weight": "1",
"category[1]": "/api/categories/79"
}
我也试过这个(这也不起作用,与前一个结果相同):
<form action="/api/data" method="post" axiosMethod="post">
<input type="text" name="weight"> <!-- value=1 -->
<input type="text" name="category[]"> <!-- value="/api/categories/2" -->
<input type="text" name="category[]"> <!-- value="/api/categories/79" -->
</form>
有谁知道我可以将两个类别值放在一个数组中?任何帮助将不胜感激
解决方案
推荐阅读
- windows - 通过添加前缀仅重命名选定的文件
- c# - 基于构造函数重载使用 Activator.CreateInstance() 创建不同的实例
- reactjs - 如何在使用 mapState 函数时使用 redux 防止 typescript 中的循环类型引用和连接?
- java - 如何使用 Selenium 和 Java 在动态列表中选择最后一个选项
- javascript - 将元素拖放到鼠标位置
- python - 具有多个条件的嵌套列表
- reactjs - 修复 iPhone 中 React 应用程序的 QR 码扫描问题
- python - NotImplementedError:Layer ModuleWrapper 在 `__init__` 中有参数,因此必须覆盖 `get_config`
- php - 如何在 Woocommerce 表单结帐中删除 html 标记
- node.js - GMail API:如何使用 nodemailer 发送电子邮件的内容