我正在使用地图(几个地图在嵌套的 json 中获取必要的元素)函数。我正在尝试根据所需的模板从 Neo4j 数据库中获取输出。在最后一张地图中,我正在构建所需输出的一部分,并将其存储在变量中: px.segments.map(function(pathSegment){ individual_path.push({ "start": pathSegment.start.properties.name, "weight": pathSegment.relationship.properties.Weight.low, "end": pathSegment.end.properties.name}); })然后我尝试: console.log(individual_path);我收到以下响应(因为其中一条记录在数据库中具有空值):[ { start: 'A', weight: 0.6180339887498948, end: 'P2' } ][][ { start: 'P1', weight: 0.6180339887498948, end: 'A' }, { start: 'A', weight: 0.6180339887498948, end: 'P2' } ][ { start: 'P1', weight: 0.6180339887498948, end: 'A' } ]我的问题是,如何用非空替换空数组(在循环记录集时),如下所示:[ { start: 'A', weight: 0.0, end: 'A' } ]最后有类似的东西:[ { start: 'A', weight: 0.6180339887498948, end: 'P2' } ] *[ { start: 'A', weight: 0.0, end: 'A' } ]*[ { start: 'P1', weight: 0.6180339887498948, end: 'A' }, { start: 'A', weight: 0.6180339887498948, end: 'P2' } ][ { start: 'P1', weight: 0.6180339887498948, end: 'A' } ]我不是很清楚,我会添加console.log(px); 输出:Path { start: Node { identity: Integer { low: 1, high: 0 }, labels: [ 'concept' ], properties: { name: 'A', type: 'string' } }, end: Node { identity: Integer { low: 2, high: 0 }, labels: [ 'concept' ], properties: { name: 'P2', type: 'string' } }, segments: [ PathSegment { start: [Object], relationship: [Object], end: [Object] } ], length: 1 }Path { start: Node { identity: Integer { low: 1, high: 0 }, labels: [ 'concept' ], properties: { name: 'A', type: 'string' } }, end: Node { identity: Integer { low: 1, high: 0 }, labels: [ 'concept' ], properties: { name: 'A', type: 'string' } }, segments: [], length: 0 }Path { start: Node { identity: Integer { low: 0, high: 0 }, labels: [ 'concept' ], properties: { name: 'P1', type: 'string' } }, end:如您所见,其中一个块有一个空元素段,即第二个路径块。我需要的是能够用类型的对象替换空元素(开始:'',重量:,结束:'')
添加回答
举报
0/150
提交
取消