reactjs - 如何从自动完成复选框传递选定的项目?
问题描述
我想将选定的项目保存到文件中。为什么这段代码不起作用?这里有保存数据的功能:
const onSubmitChecked = (selectedRoles, file) => {
const fileData = JSON.stringify(selectedRoles);
const blob = new Blob([fileData], { type: "text/plain" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.download = `${file}.json`;
link.href = url;
link.click();
};
这里有复选框:
<AutoComplete
multiple
id="checkboxes-tags-demo"
options={props.roles}
disableCloseOnSelect
getOptionLabel={(options) => `${options}`}
renderOption={(options, { selected }) => (
<React.Fragment>
<Checkbox
icon={icon}
checkedIcon={checkedIcon}
style={{ marginRight: 20 }}
checked={selected}
/>
{props.roles}
</React.Fragment>
)}
style={{ width: 500 }}
renderInput={(params) => (
<TextField
{...params}
variant="outlined"
label=""
placeholder="Available Roles"
/>
)}
/>
<button type="submit" onClick={onSubmitChecked}>
Save
</button>
但是当我运行此代码时,出现以下错误:TypeError:将循环结构转换为 JSON --> 从带有构造函数“HTMLButtonElement”的对象开始 | 属性 '__reactFiber$l9vrne8ayg' -> 带有构造函数 'FiberNode' 的对象 --- 属性 'stateNode' 关闭了圆圈
解决方案
推荐阅读
- jquery - 字体真棒图标不会移动
- ios - 添加注释权限后获取无效的代码签名权利(iOS 13)
- facebook - Azure Functions 和 Facebook 登录
- c# - C# 中的 Windows 10 语言更改弹出菜单焦点问题
- github - Git 文件夹在 github 存储库中看起来是灰色的
- r - R tidyverse,将数据重塑为每个主题一行,但有几列受到影响
- verilog - 如何在 Verilog 中实例化具有 reg 端口的模块?
- haskell - 学习 Haskell 并想做一个反向波兰符号评估器
- node.js - 'graphql' 不是内部或外部命令、可运行程序或批处理文件。在部署棱镜时
- php - 在登录表单下拉菜单中列出已经注册的用户 - 终极会员插件