是否可以在同一类型的多个结构上牢固地映射一个键?

时间:2019-03-28 13:17:19

标签: struct mapping blockchain ethereum solidity

我试图将一个地址映射到属于同一地址的多个相同类型的结构上。如果以后我想为一个地址选择任何“存储的”结构,该怎么做?

我创建了一个名为Prescription的结构,并绘制了患者地址的映射。因此,我真正想要的是将患者地址映射到几个处方结构。

struct Prescription {
    address patients_address;
    string medicament;
    string dosage_form;
    uint amount;
    uint date;
}

mapping (address => Prescription) ownerOfPrescription;

address [] public patients;

function createPrescription(address patients_address, string medicament, string dosage_form, uint amount, uint date) public restricted {
    var newPrescription = ownerOfPrescription[patients_address];

    newPrescription.medicament = medicament;
    newPrescription.dosage_form = dosage_form;
    newPrescription.amount = amount;
    newPrescription.date = date;

    patients.push(patients_address) -1;
}

function getPre(address _address)view public returns (string, string, uint, uint){ 
    return( 
        ownerOfPrescription[_address].medicament, 
        ownerOfPrescription[_address].dosage_form, 
        ownerOfPrescription[_address].amount, 
        ownerOfPrescription[_address].date);
}

现在我有了一个功能,可以在其中调用一位患者的所有书面处方。实际上,我只能呼叫一个地址的最后书面处方。

1 个答案:

答案 0 :(得分:0)

当然, { viewType: any='hybrid'; //for default 'hybrid' lat: number = 28.6330; lng: number = 77.2194; } 的值类型可以是数组:

mapping