我有一个界面如下:
interface orderItem {
symbol: string,
side: string,
price: number
quantity: number
}
Run Code Online (Sandbox Code Playgroud)
我想在我的构造函数中创建一个由“orderItems”组成的数组“orders”。
但是, orders : [orderItem] 似乎并没有做到这一点。有谁知道我该如何继续?
这是我在构造函数中尝试执行的操作:
this.state = {
orders: orderItem []
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用FileReader读取文件:
async readFile(event: any) {
var file = event.target.files[0];
var data:string
if (file) {
var reader:FileReader = new FileReader();
reader.onload = async function (evt : FileReaderEvent) {
data = await evt.target.result;
console.log(evt.target.result);
};
console.log(file);
console.log(data);
await reader.readAsText(file);
await this.processFileContent(data);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,evt.target.result仍然在我的console.log(file)调用后被打印。
有谁知道我如何获得文件结果并将其传递给我的processFileContent函数?
我正在尝试使用以下命令执行获取请求:
router.get('/marketUpdates',((request, response) => {
console.log("market updates");
var data: Order[]
axios.get('http://localhost:8082/marketUpdates')
.then(function (response) {
console.log("GET Response")
console.log(response.data);
data = response.data;
})
.catch(function (error) {
console.log("Error in fetching market updates");
});
console.log("Data before sending is ")
console.log(data);
response.send(data);
}))
Run Code Online (Sandbox Code Playgroud)
但是,我靠近底部的console.log在.then中的console.log之前执行。
数据在发送时是不确定的。有谁知道我能避免这种情况?
我正在尝试通过执行以下操作在我的反应组件中的单独行上显示一个字符串数组:
<div>
{this.props.notifications.join('\n')}
</div>
Run Code Online (Sandbox Code Playgroud)
但是,这似乎不起作用。this.props.notifications 是我想在 div 中呈现的字符串数组。有谁知道我该如何解决这个问题?