我对使用 React 真的很陌生,我使用 IntelliJ 作为我的 IDE。
我试图在我的网站上显示 JSON 数据文件的内容,但我收到错误消息,说我创建了非法导入减速。
import PostData from "./JSONData.js";
Run Code Online (Sandbox Code Playgroud)
我在类中加载信息的类如下
class Invoice extends React.Component
{
render()
{
return (
<div className ="container">
<h2>Allstate NI Graduate Application</h2>
<h2>Invoice</h2>
{PostData.map((postDetail, index)=>{
return <h1>{postDetail.code}</h1>
})}
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的主要 HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Gerry Byrne and David Wilson - ReactJS Tutorials</title>
<img src="../Drawable/carImage.png" id="carImg">
<!--Bootstap CSS-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"
integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4"
crossorigin="anonymous">
<!-- Tells the file to get the react.js file from a CDN.-->
<script …Run Code Online (Sandbox Code Playgroud) 我正在尝试计算考勤应用程序的持续时间列表的总和。我能够计算出 2 次的差异,但不确定如何遍历列表以将日期相加。
下面的代码是我到目前为止所尝试的。列表中有 2 个持续时间,它们使用对象类从 Firebase 添加到列表中。
持续时间 1 = 0:5:42
持续时间 2 = 0:0:09
预期总数 = 0:5:51
//初始化
long sum;
Run Code Online (Sandbox Code Playgroud)
//当前方法尝试
public void grandTotal() throws ParseException {
java.util.Date date1;
java.util.Date date2;
DateFormat formatter = new SimpleDateFormat("hh:mm:ss");
for(int i = 0 ; i < newList.size(); i++) {
String str_time1 = newList.get(i).getDuration();
date1 = formatter.parse(str_time1);
for (int j = 1; j < newList.size(); j++) {
String str_time2 = newList.get(j).getDuration();
date2 = formatter.parse(str_time2);
sum = date1.getTime() + date2.getTime();
}
}
secs …Run Code Online (Sandbox Code Playgroud)