0
    pragma solidity ^0.4.4;


contract heheBox { 

    struct DataBox {
        mapping(address => string) Data_01;
        mapping(address => string) Data_02;
    }

    mapping(address => DataBox) DataBox_hehe;

    function save(string _InputData_01, string _InputData_02) public  {
        DataBox_hehe[msg.sender].Data_01[msg.sender] = _InputData_01;
        DataBox_hehe[msg.sender].Data_02[msg.sender] = _InputData_02;           
    }   

    function display(address _address) constant public returns (struct) {
        return DataBox_hehe[_address];         
    }   

}

I wish the function display to display the mapping DataBox_hehe but it doesn't. Can anyone can teach me how can do this?

thank you very much!! enter image description here

0

Instead of returning structs (which would be returns(DataBox)) return individual elements. This keeps it compatible with other contracts.

Try this:

contract heheBox { 

    struct DataBox {
        mapping(address => string) Data_01;
        mapping(address => string) Data_02;
    }

    mapping(address => DataBox) DataBox_hehe;

    function save(string _InputData_01, string _InputData_02) public  {
        DataBox_hehe[msg.sender].Data_01[msg.sender] = _InputData_01;
        DataBox_hehe[msg.sender].Data_02[msg.sender] = _InputData_02;
    }   

    function display(address addressBox, address addressMap) constant public returns(string, string) {
        return(DataBox_hehe[addressBox].Data_01[addressMap], DataBox_hehe[addressBox].Data_02[addressMap]);
    }   

}

Hope it helps.

3
  • Rob Hitchens my teacher thank you so much it is work but my original hope is get the one struct mapping i think this will thrift the gas Do you think it is ture? anyway i am thank you so much for you comment!! Mar 24 '18 at 7:29
  • You should consider leaving 'mappings` where they are. Instead, consider passing keys around. It is possible to return a dynamic array (of keys) but there are non-trivial limitations and it would almost always be more costly than one-key-at-a-time, as needed. You may be looking for a Mapped Structs with Index over here: ethereum.stackexchange.com/questions/13167/… or even thinking about medium.com/@robhitchens/… Mar 24 '18 at 16:27
  • thank you very much ,this complete is my need answer medium.com/@robhitchens/… Mar 25 '18 at 4:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.