首页 > 解决方案 > 看跌期权后资产中的信息消失

问题描述

我在超级账本作曲家工作。在模型 cto 上,我定义了一个包含疫苗列表的资产 Child。该资产定义为:

asset Child identified by childId {
      o String childId
      o String name
      o String surname
      o DateTime dateOfBirth
      o Vaccin[] vaccins optional
      --> Parent hasparent
      --> Doctor hasdoctor
    }

asset defVaccin identified by vaccinId { o String vaccinId o String diseases o Integer timeFirst o Integer timeSecond optional o Integer timeThird optional o Integer timeFourth optional o Integer timeFifth optional }

为了在这个列表中创建/添加疫苗,我使用了一个事务“vaccinate”,它在模型 cto 上定义如下:

transaction Vaccinate {
  --> Child inchild 
  --> defVaccin aboutvaccin
  o DateTime dateOfVaccin
}

像这样在 logic.js

function vaccinate(vaccinate) {

var factory = getFactory();
var vaccin = factory.newConcept('vaccinspace', 'Vaccin', vaccinate.aboutvaccin.vaccinId); // create vaccin concept

// define value of concept's properties
vaccin.vaccinId = vaccinate.aboutvaccin.vaccinId;
vaccin.dateOfVaccin = vaccinate.dateOfVaccin;

// add this vaccine at the list of child's vaccines
vaccinate.inchild.addArrayValue("vaccins", vaccin)

return getAssetRegistry('vaccinspace.Child')
.then (function (assetRegistry) {
return assetRegistry.update(vaccinate.inchild); // update the list of child's vaccines
});
}

这很好用,我的清单里有我所有的疫苗。但是如果我修改了我的孩子或我的疫苗(例如,只是做一个改变孩子的名字),我之后会有一个空列表。

有人知道为什么我的信息会从我的列表中“消失”吗?我怎样才能改变这个?

标签: hyperledger-composer

解决方案


请参阅此处的示例-> https://github.com/hyperledger/composer-sample-networks/blob/master/packages/carauction-network/lib/logic.js#L89

尝试

// add this vaccine to the list of child's vaccines array of concepts
vaccinate.inchild.vaccins.push(vaccin);

代替

 // add this vaccine at the list of child's vaccines
vaccinate.inchild.addArrayValue("vaccins", vaccin);

推荐阅读