Since struct cannot be output from solidity to web3js, I'm using arrays, I could get single datatype array in the below code(userAddress), but I'm not able to take multiple value in array(userName,userTarget).Any suggestions howto would be great
Solidity:
struct Person
{
address userAddress;
string userName;
uint userTarget;
}
mapping (uint => person) Persons;
uint[] public personAccounts;
uint incr = 0;
function setDetailse(string data, uint target) public
{
uint icr = incr++;
address _address = msg.sender;
var person = persons[icr];
person .userAddress = _address;
person .userName= _vote;
person .userTarget = target;
person Accounts.push(icr) -1;
}
function getPerson() view public returns(uint[])
{
uint256[] memory data = new uint256[](11);
for(uint i = 1; i<=10 ;i++)
{
data[i]=personAccounts[i];
}
return data;
}
web3js:
GetDetails: function(Data, account) {
event.preventDefault();
var dataInstance;
web3.eth.getAccounts(function(error, accounts) {
if (error) {
console.log(error);
}
var account = accounts[0];
App.contracts.Details.deployed().then(function(instance) {
dataInstance= instance;
return dataInstance.getPerson();
}).thenfunction((numbers => {
const [ nums ] = numbers;
for (var i = 0; i <nums.length; i++)
{
console.log("address: "+nums[i]);
}
})).catch(function(err) {
console.log("error executed");
});
});