最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

如何使用Javascript更改Azure函数中的对象格式

IT培训 admin 5浏览 0评论

如何使用Javascript更改Azure函数中的对象格式

我有一个azure函数,负责调用“someStoreprocedure”并将req作为对象传递。

这个相同的req被插入到azure集合中

req中的数据如下

`{
    "intObjectName" : "JCI-AOMS-SWM",
    "aomsOrderReleaseNbr" : "7232046001",
    "shipToFaxNbr" : "7325609699",
    "50records" : [ {
        "aomsLineNbr" : 1,
        "planShipPtShipDate" : "20170101",
        "product" : {
            "name" : "test-product-train",
            "productDisplayName" : "test-product-train-display",
            "sku" : "TRAIN-SKU",
        },
        "licenses" : [ {
            "productKey" : "productKey-1",
            "status" : "not activated"
        }, {
            "productKey" : "productKey-2",
            "status" : "not activated"
        },

        {
            "productKey" : "productKey-3",
            "status" : "not activated"
        } ]
    } ],
    "isEntitlementInProgress" : true,
    "id" : "1dcf296e-4e2f-b3f5-8117-92a7879e0a9b"
}` 

我想将其更改为不同的格式,如下所示,只需要发送到存储过程插入即可。

`{
intObjectName: "JCI-AOMS-SWM"
productKeys: [
{
            "productKey" : "productKey-1",
            "status" : "not activated"
},
{
            "productKey" : "productKey-1",
            "status" : "not activated"
},
{
            "productKey" : "productKey-1",
            "status" : "not activated"
},
]
}` 

我的JS代码如下,

请告知我代码中的更正。

var DocumentDBClient = require('documentdb').DocumentClient;
module.exports = function(context, req) {
    var host = "some";
    var masterKey = "some=";
    var spName = "someStoreprocedure";
    var client = "";
    client = new DocumentDBClient(host, {
        masterKey : masterKey
    });

    var insertSPLink = "dbs/" + "admin" + "/colls/" + "productsoutput"
            + "/sprocs/" + spName;
    client.executeStoredProcedure(insertSPLink,req,function(err, res) {
                        if (err) {
                            return callback(statusObj);
                        } else {
                            context.log("Success in Insertion");
                            context.done();
                            return context;
                        }
                    });
};
回答如下:

例如:

var req = {
    "intObjectName": "JCI-AOMS-SWM",
    "aomsOrderReleaseNbr" : "7232046001",
    "shipToFaxNbr" : "7325609699",
    "50records" : [ {
        "aomsLineNbr" : 1,
        "planShipPtShipDate" : "20170101",
        "product" : {
            "name" : "test-product-train",
            "productDisplayName" : "test-product-train-display",
            "sku" : "TRAIN-SKU",
        },
        "licenses" : [ {
            "productKey" : "productKey-1",
            "status" : "not activated"
        }, {
            "productKey" : "productKey-2",
            "status" : "not activated"
        },

        {
            "productKey" : "productKey-3",
            "status" : "not activated"
        } ]
    } ],
    "isEntitlementInProgress" : true,
    "id" : "1dcf296e-4e2f-b3f5-8117-92a7879e0a9b"
};

var formatedReq = {
    intObjectName: req["intObjectName"],
    productKeys: req["50records"][0]["licenses"]
}

console.log(formatedReq);

输出:

{
    intObjectName: 'JCI-AOMS-SWM',
    productKeys: [
        {
            productKey: 'productKey-1',
            status: 'not activated'
        },
        {
            productKey: 'productKey-2',
            status: 'not activated'
        },
        {
            productKey: 'productKey-3',
            status: 'not activated'
        }
    ]
}

如何使用Javascript更改Azure函数中的对象格式

我有一个azure函数,负责调用“someStoreprocedure”并将req作为对象传递。

这个相同的req被插入到azure集合中

req中的数据如下

`{
    "intObjectName" : "JCI-AOMS-SWM",
    "aomsOrderReleaseNbr" : "7232046001",
    "shipToFaxNbr" : "7325609699",
    "50records" : [ {
        "aomsLineNbr" : 1,
        "planShipPtShipDate" : "20170101",
        "product" : {
            "name" : "test-product-train",
            "productDisplayName" : "test-product-train-display",
            "sku" : "TRAIN-SKU",
        },
        "licenses" : [ {
            "productKey" : "productKey-1",
            "status" : "not activated"
        }, {
            "productKey" : "productKey-2",
            "status" : "not activated"
        },

        {
            "productKey" : "productKey-3",
            "status" : "not activated"
        } ]
    } ],
    "isEntitlementInProgress" : true,
    "id" : "1dcf296e-4e2f-b3f5-8117-92a7879e0a9b"
}` 

我想将其更改为不同的格式,如下所示,只需要发送到存储过程插入即可。

`{
intObjectName: "JCI-AOMS-SWM"
productKeys: [
{
            "productKey" : "productKey-1",
            "status" : "not activated"
},
{
            "productKey" : "productKey-1",
            "status" : "not activated"
},
{
            "productKey" : "productKey-1",
            "status" : "not activated"
},
]
}` 

我的JS代码如下,

请告知我代码中的更正。

var DocumentDBClient = require('documentdb').DocumentClient;
module.exports = function(context, req) {
    var host = "some";
    var masterKey = "some=";
    var spName = "someStoreprocedure";
    var client = "";
    client = new DocumentDBClient(host, {
        masterKey : masterKey
    });

    var insertSPLink = "dbs/" + "admin" + "/colls/" + "productsoutput"
            + "/sprocs/" + spName;
    client.executeStoredProcedure(insertSPLink,req,function(err, res) {
                        if (err) {
                            return callback(statusObj);
                        } else {
                            context.log("Success in Insertion");
                            context.done();
                            return context;
                        }
                    });
};
回答如下:

例如:

var req = {
    "intObjectName": "JCI-AOMS-SWM",
    "aomsOrderReleaseNbr" : "7232046001",
    "shipToFaxNbr" : "7325609699",
    "50records" : [ {
        "aomsLineNbr" : 1,
        "planShipPtShipDate" : "20170101",
        "product" : {
            "name" : "test-product-train",
            "productDisplayName" : "test-product-train-display",
            "sku" : "TRAIN-SKU",
        },
        "licenses" : [ {
            "productKey" : "productKey-1",
            "status" : "not activated"
        }, {
            "productKey" : "productKey-2",
            "status" : "not activated"
        },

        {
            "productKey" : "productKey-3",
            "status" : "not activated"
        } ]
    } ],
    "isEntitlementInProgress" : true,
    "id" : "1dcf296e-4e2f-b3f5-8117-92a7879e0a9b"
};

var formatedReq = {
    intObjectName: req["intObjectName"],
    productKeys: req["50records"][0]["licenses"]
}

console.log(formatedReq);

输出:

{
    intObjectName: 'JCI-AOMS-SWM',
    productKeys: [
        {
            productKey: 'productKey-1',
            status: 'not activated'
        },
        {
            productKey: 'productKey-2',
            status: 'not activated'
        },
        {
            productKey: 'productKey-3',
            status: 'not activated'
        }
    ]
}
发布评论

评论列表 (0)

  1. 暂无评论