我正在制作一份报告,其中用户从xml读取数据并推送数据。
我在处理从xml中获取的值的数据集时遇到问题。现在我正在创建一个对象 deMapping ,其中会有不同的来源,比如我在代码中提到过的RBSK。从RBSK开始,它将读取xml中存在的所有标签,如 Childhood_Diseases_0_6_Female 现在我已经在我们想要推送数据的服务器端映射了特定的dataelemt和category。 喜欢(xmlid,dataelement,categoryOptionCombo)。它是一个长数组 des []
现在点击按钮我正在调用prepareataset函数。在这里我想将值从xml推送到我正在创建的集合,但在这里我想在deMapping中推送上面定义的特定xmlid值和dataelement和类别。但是根据以下函数它只需要数组des []的最后一个值作为resObj [prop],我想推送像上面映射的所有值。任何人都可以告诉我的方式吗? 主要部分是调用函数的for循环。
function prepareDataValueSet() {
var deMapping = {
RBSK: {
'dsUID': 'tdTwLUxcQ8R', rootNodeName: 'RBSK_GIS_Indicator', orgUnitTagName: 'MCTSCode', des: [
{
xmlid: "Childhood_Diseases_0_6_Female",
dataElement: "oV163sbcJ0N",
categoryOptionCombo: "Cmzbo9LD8pJ"
},
{
xmlid: "Childhood_Diseases_0_6_Male",
dataElement: "oV163sbcJ0N",
categoryOptionCombo: "PnAVAPG4yvb"
},
{
xmlid: "Childhood_Diseases_7_18_Female",
dataElement: "cEPledgs7rd",
categoryOptionCombo: "Cmzbo9LD8pJ"
},
{
xmlid: "Childhood_Diseases_7_18_Male",
dataElement: "cEPledgs7rd",
categoryOptionCombo: "PnAVAPG4yvb"
},
{ xmlid: "Deficiencies_0_6_Female", dataElement: "gKupqkIhW4n", categoryOptionCombo: "Cmzbo9LD8pJ" },
{ xmlid: "Deficiencies_0_6_Male", dataElement: "gKupqkIhW4n", categoryOptionCombo: "PnAVAPG4yvb" },
{ xmlid: "Deficiencies_7_18_Female", dataElement: "FuEnn0bLuoT", categoryOptionCombo: "Cmzbo9LD8pJ" },
{ xmlid: "Deficiencies_7_18_Male", dataElement: "FuEnn0bLuoT", categoryOptionCombo: "PnAVAPG4yvb" },
{
xmlid: "Developmental_dealy_and_disability_0_6_Female",
dataElement: "v37HBq7C72j",
categoryOptionCombo: "Cmzbo9LD8pJ"
},
{
xmlid: "Developmental_dealy_and_disability_0_6_Male",
dataElement: "v37HBq7C72j",
categoryOptionCombo: "PnAVAPG4yvb"
},
{
xmlid: "Developmental_dealy_and_disability_7_18_Female",
dataElement: "S1WMlAKnF8Z",
categoryOptionCombo: "Cmzbo9LD8pJ"
},
{
xmlid: "Developmental_dealy_and_disability_7_18_Male",
dataElement: "S1WMlAKnF8Z",
categoryOptionCombo: "PnAVAPG4yvb"
},
{
xmlid: "defect_at_birth_0_6_Female",
dataElement: "JJO3utHjb3l",
categoryOptionCombo: "Cmzbo9LD8pJ"
},
{ xmlid: "defect_at_birth_0_6_Male", dataElement: "JJO3utHjb3l", categoryOptionCombo: "PnAVAPG4yvb" },
{
xmlid: "defect_at_birth_7_18_Female",
dataElement: "qoVmtykHboz",
categoryOptionCombo: "Cmzbo9LD8pJ"
},
{ xmlid: "defect_at_birth_7_18_Male", dataElement: "qoVmtykHboz", categoryOptionCombo: "PnAVAPG4yvb" }
]
}
}
var dataValueSet = {};
var dataValues = [];
for (var i = 0; i < mstc.length; i++) {
if (map[mstc[i]] == undefined) {
msg += "," + +mstc[i];
console.log(msg);
}
else if (dmap[map[mstc[i]]] != undefined) {
for (var prop in deMapping) {
var source = deMapping[prop]; //Source=RBSK
for (var dataset in source) {
if (dataset === "des") {
source[dataset].forEach(function (resObj) {
for (var prop in resObj) {
console.debug(prop, ":", resObj[prop]);
var dataValue = {};
dataValue["period"] = "201509";
dataValue["dataElement"] = resObj[prop];
dataValue["categoryOptionCombo"] = 'resObj[prop]';
dataValue["value"] = mapDataValue[mstc[i] + ":" + 'resObj[prop]'];
}
dataValues.push(dataValue);
dataValueSet.dataValues = dataValues;
console.log(JSON.stringify(dataValueSet));