我正在使用 javascript 协调 MarkLogic 中的数据。目前,对于我的输出,我能够显示所有子元素Activity
,但问题是父元素Activities
也被重复显示。
这是当前输出,<Activities>
仅出现在每个Activity
:
<Activities datatype="array">
<Activity>
<ActivityCrewSize>10</ActivityCrewSize>
<ActivitySeqNo>1</ActivitySeqNo>
<ActivityDesc/>
</Activity>
</Activities>
<Activities datatype="array">
<Activity>
<ActivityCrewSize>23</ActivityCrewSize>
<ActivitySeqNo>2</ActivitySeqNo>
<ActivityDesc/>
</Activity>
</Activities>
<Activities datatype="array">
<Activity>
<ActivityCrewSize>50</ActivityCrewSize>
<ActivitySeqNo>3</ActivitySeqNo>
<ActivityDesc/>
</Activity>
</Activities>
这是我想要的输出,<Activities>
只出现一次
<Activities datatype="array">
<Activity>
<ActivityCrewSize>10</ActivityCrewSize>
<ActivitySeqNo>1</ActivitySeqNo>
<ActivityDesc/>
</Activity>
<Activity>
<ActivityCrewSize>23</ActivityCrewSize>
<ActivitySeqNo>2</ActivitySeqNo>
<ActivityDesc/>
</Activity>
<Activity>
<ActivityCrewSize>50</ActivityCrewSize>
<ActivitySeqNo>3</ActivitySeqNo>
<ActivityDesc/>
</Activity>
</Activities>
以下是我当前输出的当前代码:
obj.Activities = [];
let act = {
'$type': 'Activity',
'$version': '0.0.1',
}
for (const item of activities) {
act.ActivityCrewSize = fn.normalizeSpace(hl.elementText(item, "CrewSize", true));
act.ActivitySeqNo = fn.normalizeSpace(hl.elementText(item, "SeqNo", true));
act.ActivityDesc = hl.elementText(item, null, true);
obj.Activities.push(act);
}
return obj;