weixin_41584177
2019-08-29 11:14
采纳率: 83.3%
浏览 1.5k

微信小程序中关于返回数据的操作

请问如何在服务器返回的数据中提取出我需要的那部分
以下是服务器返回的数据

    [{
      "procDef.name": "请假流程",
      "task.assignee": "admin",
      "task.executionId": "a25a1287decc4aea97fda5c8c4a49e4a",
      "task.name": "领导审核",
      "count": "11",
      "task.createTime": 1558608917000,
      "procDef.version": 5,
      "task.id": "ffbf1b3ca9f543eea2402d3c365900e2",
      "task.taskDefinitionKey": "node0",
      "task.processInstanceId": "a25a1287decc4aea97fda5c8c4a49e4a",
      "vars": {
        "busId": "ad629b4986a34f0bace9892cfc1b8788",
        "type": "tealeave",
        "title": "11",
        "applyUserId": "张大壮"
      },
      "status": "todo"
    }, {
      "procDef.name": "请假流程",
      "task.assignee": "admin",
      "task.executionId": "e8065adf4db344fc92165c732ed85156",
      "task.processDefinitionId": "tealeave:5:e1b5cc7f26744495b7340434876fc8fc",
      "task.name": "领导审核",
      "count": "11",
      "task.createTime": 1557399272000,
      "procDef.version": 5,
      "task.id": "99f7797ddad14969ad477a050fcee336",
      "task.taskDefinitionKey": "node0",
      "task.processInstanceId": "e8065adf4db344fc92165c732ed85156",
      "vars": {
        "busId": "288dee733e074e73becbd5bf889b2447",
        "type": "tealeave",
        "title": "youshi",
        "applyUserId": "lilaoshi"
      },
      "status": "todo"
    }, {
      "procDef.name": "请假流程",
      "task.assignee": "admin",
      "task.executionId": "5fcb2da62b8042dfaae7a6dead57eb3b",
      "task.processDefinitionId": "tealeave:5:e1b5cc7f26744495b7340434876fc8fc",
      "task.name": "领导审核",
      "count": "11",
      "task.createTime": 1557392981000,
      "procDef.version": 5,
      "task.id": "0efe25339021449e9583c9e6395a1ea4",
      "task.taskDefinitionKey": "node1",
      "task.processInstanceId": "5fcb2da62b8042dfaae7a6dead57eb3b",
      "vars": {
        "busId": "5f88a073e4294cc78116011a3667a070",
        "node0Pass": true,
        "title": "噢噢噢噢哦哦哦哦哦哦",
        "type": "tealeave",
        "applyUserId": "李三"
      }]

我只需要这些数据中几项
"procDef.name","task.name","task.createTime",还有"vars"中的"applyUserId"
放入我下面的数据中:

     info: [{
      "proccessname": "请假",
      "curretprocess": "领导审核",
      "createTime": 1557399272000,
      "applyUserId": "张xx"
      }]

直接赋值会有问题 比如proccessname=list[0].procDef.name 后面的name会报错说undefined ,请问如何处理

另外 proccessname 只有前个字 比如'请假流程'只留'请假'2字

createTime时间戳转换到年-月-日格式

谢谢 新手真不太会

  • 点赞
  • 收藏

2条回答 默认 最新

  • Tiarnach 2019-08-29 13:21
    已采纳
        var src=你的数据
        var desc=[];//你要的数据
        src.forEach((data)=>{
              desc.push({
                  "proccessname": data["procDef.name"].substring(0,2),
                  "curretprocess": data["task.name"],
                  "createTime":  new Date(parseInt(data["task.createTime"])).toUTCString(),
                  "applyUserId": data["vars"]["applyUserId"]
              });
          });
    
    
    

    最终的desc:

    
    [
        {
            "proccessname":"请假",
            "curretprocess":"领导审核",
            "createTime":"Thu, 23 May 2019 10:55:17 GMT",
            "applyUserId":"张大壮"
        },
        {
            "proccessname":"请假",
            "curretprocess":"领导审核",
            "createTime":"Thu, 09 May 2019 10:54:32 GMT",
            "applyUserId":"lilaoshi"
        },
        {
            "proccessname":"请假",
            "curretprocess":"领导审核",
            "createTime":"Thu, 09 May 2019 09:09:41 GMT",
            "applyUserId":"李三"
        }
    ]
    
    
    点赞 1 打赏 评论
  • i冇心 2019-08-29 11:44

    获取到数据后处理:
    var list = 你获取的数据列表;
    var newlist = []; // 新的数据列表
    for (var i = 0; i < list.length; i++) {
    var singledata = {
    "proccessname": list[i].procDef.name,
    "curretprocess": list[i].task.name,
    "createTime": list[i].task.createTime,
    "applyUserId": list[i].vars.applyUserId,
    }
    newlist.push(singledata);
    }

    得到的newlist就是你想要的数据,大概思路就是这样。
    另外 proccessname 只有前个字 time还能转换到正常格式 , 这个我是这没看懂。

    希望对你有帮助,如果对你有帮助的话,请你去我主页帮我的文章点赞评论一下,谢谢。

    有什么问题可以继续问我。

    点赞 打赏 评论

相关推荐 更多相似问题