对象分配嵌套属性Javascript

时间:2019-10-15 07:21:03

标签: javascript reactjs

我是React JS(Javascript)的新手,在合并以前的记录和分页中的新记录时遇到问题。

下面是代码:-

首页结果

fib_n_minus_2 + fib_n_minus_1

第二页结果

n

最终结果应类似于下面的JSON

{
  "status": 200,
  "error": null,
  "message": null,
  "result": {
    "data": [{
      "SuraID": 116,
      "ChapterID": 2,
      "SuraName": "The Cow",
      "Sajda": 0,
      "Ayah": 286,
      "Latin": "Al-Baqara",
      "AyahText": [{
          "id": 6283,
          "text": "O children of Israel, remember the favours I bestowed on you. So keep your pledge to Me, and I will mine to you, and be fearful of Me, ",
          "found": "1"
        },
        {
          "id": 6290,
          "text": "Remember, O children of Israel, the favours I bestowed on you, and made you exalted among the nations of the world. ",
          "found": "1"
        }
      ]
    }],
    "totalFound": 598,
    "prev_page_url": "1",
    "next_page_url": 2,
    "totalPages": 27,
    "percentage": 0.38390180331131357
  }

1 个答案:

答案 0 :(得分:0)

伪代码:

let firstPageData = //from 1 fetch and after JSON.parse(data);
let secondPageData = //from 2 fetch and after JSON.parse(data);

let mergedPage= [...firstPageData,...secondPageData ];

let  mergedPage= firstPageData.concat(secondPageData);