我试图通过固执合同来调用一个函数,并在控制台中记录结果(返回数组或以固结方式进行映射)。
import React, {Component} from "react";
class Select extends Component {
constructor(props) {
super(props);
this.state = this.props.data;
}
getSuppliers = async (event) => {
const { accounts, contract, productId } = this.state;
await contract.methods.getSuppliersOfProduct(productId).call({ from: accounts[0] }, (err,result) => {
if(err){
console.log("Error at product: ", err);
}
else {
console.log("Result: ", result);
}
});
}
changeHandler = (event) => {
const { name, value } = event.target;
this.setState({ [name]: value });
};
render() {
return(
<div className="App">
<input
name="productId"
value={this.state.productId}
onChange={this.changeHandler}
placeholder="Product ID"
/>
<button onClick={this.getSuppliers}>Get Suppliers</button>
<br />
<h1>{this.state.productId}</h1>
</div>
);
}
}
export default Select;
我希望从“ getSuppliers()”函数返回的“结果”为4个地址的数组,但它仅返回2个数组,即返回数组的第一个和最后一个元素。