我在下面的代码中使用了reactJS和typescript.在执行命令时,我得到以下错误.
我还添加了import语句import'bootstrap/dist/css/bootstrap.min.css'; 在Index.tsx中.
有没有办法解决这个问题?
npm start
client/src/Results.tsx
(32,21): Missing "key" prop for element.
Run Code Online (Sandbox Code Playgroud)
该文件如下"Results.tsx"
import * as React from 'react';
class Results extends React.Component<{}, any> {
constructor(props: any) {
super(props);
this.state = {
topics: [],
isLoading: false
};
}
componentDidMount() {
this.setState({isLoading: true});
fetch('http://localhost:8080/topics')
.then(response => response.json())
.then(data => this.setState({topics: data, isLoading: false}));
}
render() {
const {topics, isLoading} = this.state;
if (isLoading) {
return <p>Loading...</p>;
}
return (
<div>
<h2>Results List</h2>
{topics.map((topic: any) =>
<div className="panel panel-default">
<div className="panel-heading" …Run Code Online (Sandbox Code Playgroud) 我试图将数据引入reactJS以及打字稿.在这样做时,我得到了以下错误
Type 'null' is not assignable to type 'HTMLInputElement'
Run Code Online (Sandbox Code Playgroud)
请告诉我这里究竟有什么不正确的地方,我使用了React https://reactjs.org/docs/refs-and-the-dom.html中的 documentaiton, 但我觉得我在这里做错了.以下是范围片段
class Results extends React.Component<{}, any> {
private textInput: HTMLInputElement;
.......
constructor(props: any) {
super(props);
this.state = { topics: [], isLoading: false };
this.handleLogin = this.handleLogin.bind(this);
}
componentDidMount() {.....}
handleLogin() {
this.textInput.focus();
var encodedValue = encodeURIComponent(this.textInput.value);
.......
}
render() {
const {topics, isLoading} = this.state;
if (isLoading) {
return <p>Loading...</p>;
}
return (
<div>
<input ref={(thisInput) => {this.textInput = thisInput}} type="text" className="form-control" placeholder="Search"/>
<div className="input-group-btn">
<button className="btn btn-primary" …Run Code Online (Sandbox Code Playgroud) 我必须创建一个方法,需要将文件分成多个字节。
示例 byte[] 到 List<byte[]> 中,假设每个大小为 1 MB (sizeMB=1 * 1024 * 1024)
因此 5.2 MB 文件应该由五个 1MB 和一个 2KB 组成。[2kb、1MB、1MB、1MB、1MB、1MB]。
byte[] mainFile=getFIle();
List<bute[]> listofSplitBytes=getFileChunks(mainFile);
public void list<bute[]> getFileChunks(byte[] mainFile) {
int sizeMB = 1 * 1024 * 1024;
// Split the files logic
}
Run Code Online (Sandbox Code Playgroud)
我试图避免添加if then else来处理。我正在尝试寻找是否有更干净的方法来做到这一点,例如使用流或类似的东西?
reactjs ×2
typescript ×2
file ×1
java ×1
java-8 ×1
java-stream ×1
node.js ×1
reference ×1
split ×1