代码段——关于Jquery操作Json数组的问题

后端传递来的JSON数组

[
    {
        "id": 8,
        "wxId": "1354e021-6314-42a8-9f15-02cf686c8c81",
        "fileName": "/YDBXUploadFile/20230829164854_设备管理菜单节点.png",
        "createTime": "2023-08-29 16:48:53"
    },
    {
        "id": 9,
        "wxId": "1354e021-6314-42a8-9f15-02cf686c8c81",
        "fileName": "/YDBXUploadFile/20230829164854_设备管理菜单节点.png",
        "createTime": "2023-08-29 16:48:53"
    },
    {
        "id": 10,
        "wxId": "1354e021-6314-42a8-9f15-02cf686c8c81",
        "fileName": "/YDBXUploadFile/20230829164854_设备管理菜单节点.png",
        "createTime": "2023-08-29 16:48:53"
    },
    {
        "id": 11,
        "wxId": "1354e021-6314-42a8-9f15-02cf686c8c81",
        "fileName": "/YDBXUploadFile/20230824085733_SHU测试条码.png",
        "createTime": "2023-08-29 16:48:53"
    }
]

var imgsArray=[];
console.log(data);
$.each(data, function (index, imgModel) {
    var img = {};
    img.code = imgModel.id;
    img.path = "../" + imgModel.fileName;
    img.name = imgModel.fileName;
    imgsArray.push(img);
})

console.log(imgsArray);

结果格式如下:

[
    {
        "code": 8,
        "path": "..//YDBXUploadFile/20230829164854_设备管理菜单节点.png",
        "name": "/YDBXUploadFile/20230829164854_设备管理菜单节点.png"
    },
    {
        "code": 9,
        "path": "..//YDBXUploadFile/20230829164854_设备管理菜单节点.png",
        "name": "/YDBXUploadFile/20230829164854_设备管理菜单节点.png"
    },
    {
        "code": 10,
        "path": "..//YDBXUploadFile/20230829164854_设备管理菜单节点.png",
        "name": "/YDBXUploadFile/20230829164854_设备管理菜单节点.png"
    },
    {
        "code": 11,
        "path": "..//YDBXUploadFile/20230824085733_SHU测试条码.png",
        "name": "/YDBXUploadFile/20230824085733_SHU测试条码.png"
    }
]
posted @ 2023-09-01 16:36  shanzm  阅读(3)  评论(0编辑  收藏  举报
TOP