Reactjs 无法转换对象中值的数据类型

Reactjs 无法转换对象中值的数据类型,reactjs,mongodb,next.js,Reactjs,Mongodb,Next.js,我已经使用mongoDB作为数据库创建了next.js应用程序 现在,正如在我的代码中一样,当按下按钮时,所有数据都将显示在表中。我已经提取了我想要单独计算的所有数据,例如product\u unit和product\u price。但是,因为在productList中,该值已作为文本被push。我无法计算 我尝试使用.parseInt进行转换,但不起作用 我该怎么办 我的代码: const [jsxProductList, setJsxProductList] = useState(<t

我已经使用mongoDB作为数据库创建了next.js应用程序

现在,正如在我的代码中一样,当按下按钮时,所有数据都将显示在表中。我已经提取了我想要单独计算的所有数据,例如
product\u unit
product\u price
。但是,因为在
productList
中,该值已作为文本被
push
。我无法计算

我尝试使用
.parseInt
进行转换,但不起作用

我该怎么办

我的代码:

const [jsxProductList, setJsxProductList] = useState(<tr></tr>);
const [productList, setProductList] = useState([]);

const onSubmitToDatabase = (data) => {
    console.log({ productList })
    fetch('/api/stock',
       {
           method: 'post',
           body: productList
       })
    }

const onSubmit = (data) => {

let j = 1
for (let i = 1; i <= productList.length; i++) {
  j++
}

var start_item_id = j
let p = { id: start_item_id, product_name: data.product_name, code: data.code, brand: 'Honda', model: 'CBR150', qty: data.qty, unitPrice: 100 }
productList.push(p)
console.log("productList", productList.length)
let newList = productList.map(p => {
  console.log("Update JSX", p)
  return (
    <tr>
      <td>{p.id}</td>
      <td>{p.product_name}</td>
      <td>{p.code}</td>
      <td>{p.brand}</td>
      <td>{p.model}</td>
      <td>{p.qty}</td>
      <td>{p.unitPrice}</td>
    </tr>
  )
})
setProductList(productList)
setJsxProductList(newList)

const product_code = []
const product_price = []
const product_unit = []
productList.map(p => {
  product_code.push(p.code)
  product_price.push(p.unitPrice)
  product_unit.push(p.qty)
})

product_unit.map(h => (
  h.parseInt
))

let total_unit, total_price = 0
for (let k = 0; k < product_unit.length; k++) {
  total_unit = total_unit + product_unit[k]
}}

for (let k = 0; k < product_price.length; k++) {
  total_unit = total_unit + product_unit[k]
}}
const[jsxProductList,setJsxProductList]=useState();
const[productList,setProductList]=useState([]);
SubmittoDatabase=(数据)=>{
console.log({productList})
获取(“/api/stock”,
{
方法:“post”,
正文:产品列表
})
}
const onSubmit=(数据)=>{
设j=1
for(设i=1;i{
log(“更新JSX”,p)
返回(
{p.id}
{p.product_name}
{p.code}
{p.brand}
{p.model}
{p.qty}
{p.单价}
)
})
setProductList(产品列表)
setJsxProductList(newList)
常量产品代码=[]
常数产品价格=[]
常数乘积单位=[]
productList.map(p=>{
产品代码推送(p代码)
产品价格推送(p.单价)
产品单位推送(p.数量)
})
产品单位图(h=>(
h、 帕森特
))
设总单位,总价格=0
for(设k=0;k
试试这个:

const new_product_unit = product_unit.map(h => parseInt(h));

// now use "new_product_unit" later in your code