我需要使用 tde 模板处理一些有时缺少数据的文档。但仍需要在表格中显示。但是我的模板在返回带有空数据的文档时遇到了问题。
var doc1 = xdmp.toJSON(
{
"customer":{
"Name": "Name1",
"Addr": [
{
"AddrTypeCd": "MailingAddress",
"Addr1": "911 FORBES AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "PA",
"PostalCode": "15219"
},
{
"AddrTypeCd": "OfficeAddress",
"Addr1": "911 Watson AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "CT",
"PostalCode": "15119"
}
]
}
});
var doc2 = xdmp.toJSON(
{
"customer":{
"Name": "Name2",
"Addr": [
]
}
});
var rowtde1 = xdmp.toJSON(
{
"template":{
"context":"/customer/Addr",
"rows":[
{
"schemaName":"Schemas",
"viewName":"CustomerAddress",
"columns":[
{
"name":"CustomerName",
"scalarType":"string",
"val":"../../Name"
},
{
"name":"AddrTypeCd",
"scalarType":"string",
"val":"AddrTypeCd",
"nullable": true
},
{
"name":"Addr1",
"scalarType":"string",
"val":"Addr1",
"nullable": true
},
{
"name":"Addr2",
"scalarType":"string",
"val":"Addr2",
"nullable": true
},
{
"name":"CityName",
"scalarType":"string",
"val":"CityName",
"nullable": true
},
{
"name":"StateProvCd",
"scalarType":"string",
"val":"StateProvCd",
"nullable": true
},
{
"name":"PostalCode",
"scalarType":"string",
"val":"PostalCode",
"nullable": true
}
]
}
]
}
}
);
tde.nodeDataExtract([doc1, doc2],[rowtde1]);
对于此数据提取,响应为:
{
"document1": [
{
"row": {
"schema": "Schemas",
"view": "CustomerAddress",
"data": {
"rownum": "1",
"CustomerName": "Name1",
"AddrTypeCd": "MailingAddress",
"Addr1": "911 FORBES AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "PA",
"PostalCode": "15219"
}
}
},
{
"row": {
"schema": "Schemas",
"view": "CustomerAddress",
"data": {
"rownum": "2",
"CustomerName": "Name1",
"AddrTypeCd": "OfficeAddress",
"Addr1": "911 Watson AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "CT",
"PostalCode": "15119"
}
}
}
],
"document2": []
}
但我也需要为没有地址的客户获取响应数据,如下所示:
{ "document1": [
{
"row": {
"schema": "Schemas",
"view": "CustomerAddress",
"data": {
"rownum": "1",
"CustomerName": "Name1",
"AddrTypeCd": "MailingAddress",
"Addr1": "911 FORBES AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "PA",
"PostalCode": "15219"
}
}
},
{
"row": {
"schema": "Schemas",
"view": "CustomerAddress",
"data": {
"rownum": "2",
"CustomerName": "Name1",
"AddrTypeCd": "OfficeAddress",
"Addr1": "911 Watson AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "CT",
"PostalCode": "15119"
}
}
} ], "document2": [ {
"row": {
"schema": "Schemas",
"view": "CustomerAddress",
"data": {
"rownum": "1",
"CustomerName": "Name2"
}
}
} ] }
我是否需要创建第二个视图来处理文档中的名称,然后将其加入地址视图?多个联接会对性能产生影响吗?