javascript - 插入多行物料表
问题描述
我正在尝试在 mat 表中添加多行,因此我有一个字段,用户可以在其中引入数字,例如:“2”
然后我问他是想将它作为一行引入还是单独引入,如果一切都在一行中,它很好但是当我尝试单独添加它时它会中断并且只引入一行而不是写的数字
然后循环for并setData()
在for内部
const [data, setData] = useState([]);
const json = {
id: id,
name: null,
};
const newArr3 = [];
for (let index = 0; index < number; index++) {
newArr3.push(json);
postRequest(json);
setData(newArr3);
}
<MaterialTable
columns={columns}
data={data}
title="Table 2"
options={{
exportButton: true,
filtering: true,
actionsColumnIndex: -1,
headerStyle: {
backgroundColor: '#01579b',
color: '#FFF'
},
rowStyle: {
backgroundColor: '#EEEEEE',
}
}}
/>
我从组件反应工具开发人员那里看到它在数组中引入了 2 个对象,data
但只显示了一个,可能是因为它本来应该是相同的:tabledata {id:0}
但我不知道该怎么做。tabledata {id:0}
tabledata {id:1}
提前致谢
解决方案
尝试 ty give index
of for
loop as id
。
const newArr3 = [];
for (let index = 0; index < number; index++) {
const json = {
id: index,
name: null
}
newArr3.push(json);
postRequest(json);
setData(newArr3);
}
推荐阅读
- flutter - 即使位置是静态的(颤振),位置 onChange 函数也会不断被调用
- python - Python:将固定数组乘以元素方式的第二个数组
- python - kivy在后台运行功能
- javascript - 用d3+react画一条路径(折线图)
- html - 我正在尝试在垂直 flex div 中并排制作按钮
- angular - 在迭代表角度 8 中显示复选框的值
- ios - 如何从呈现的 ViewController 推送?
- vba - VBA项目创建子程序
- google-cloud-functions - Google Cloud Functions REST API,functions.patch 错误:必须为函数指定一个触发器
- python - 如何将缩放的分类数据添加回原始数据集?