我试图用一个这样的对象数组填充一个表:
myPacients: {name: string, pAddress: string}[];
myPacients = [
{ "John Doe", "0x0234234..."},
{ "Alex Morgan", "0x2354354..."},
...etc...
];
但是,当我尝试从Angular 6客户端应用程序填充表时,它仅显示我使用newPacient()
函数编写的最后一个对象。我的Solidity ^0.5.0
代码在松露控制台中运行良好。
我的newPacient()
函数:
async newPacient() {
let _pacientAddress = this.pacientAddress;
try {
const deployedMedBlock = await this.MedBlock.deployed();
await deployedMedBlock.newPacient(_pacientAddress, { from: myAddress });
} catch (e) {
console.log(e)
}
}
我的getAllPacients()
:
async getAllPacients() {
try {
const deployedMedBlock = await this.MedBlock.deployed();
let medBlockMedicAddresses = await deployedMedBlock.getPacientAddresses({ from: this.model.account });
this.pacientAccounts = medBlockMedicAddresses;
console.log(this.pacientAccounts);
} catch (e) {
console.log(e);
}
for (let i = 0; i < this.pacientAccounts.length; i++) {
this.getUserByAddress(this.pacientAccounts[i]).then((result) => {
this.myPacients = [
{name: result, pAddress: this.pacientAccounts[i]}[i]
];
})
}
}
}
我的getUserByAddress(userAddress)
函数
async getUserByAddress(userAddress) {
try {
const deployedMedBlock = await this.MedBlock.deployed();
let medBlockUser = await deployedMedBlock.getName(userAddress, { from: myAddress });
return medBlockUser;
} catch (e) {
console.log(e);
}
}
我应该如何从智能合约中获取所有数据并填充前端数组?