簡體   English   中英

如何從兩個 API 調用中獲取數據,將它們合並並與我的其他數據一起顯示在表格中?

[英]How to get data from two API calls, merge them and display them in a table with my other data?

因此,為了讓您了解我需要幫助的內容,

我有 3 個 HTML5 游戲,其中 2 個將數據存儲到我的 MySQL 數據庫中,我正在使用用戶的“電子郵件”作為唯一 ID 獲取他們的數據,合並重復項並在“排行榜表”中顯示它們。

第三個游戲的問題是 - 我無法直接訪問它的數據庫,游戲提供商給了我 API 訪問權限以獲取用戶數據。

他給了我兩個網址。 一個訪問用戶數據,一個訪問游戲數據。

用戶數據包括:用戶的Email(我想要的) 游戲數據包括:用戶的分數(我想要的)

在理想情況下,我會從一個 API url 中得到這兩個東西。 但我不明白。 那么如何使用 2 個 URL 編寫 API 調用,使我可以將 playerA@gmail.com 與他的分數相匹配,然后將其顯示在表格中?

以下是 API 詳細信息:

在此處輸入圖像描述

在此處輸入圖像描述

我想從排行榜 API 調用中獲取用戶名 + 分數。 我想從用戶 API 調用中獲得分數。 然后將它們存儲/顯示在我的數據表中。 請指導我如何完成這項工作。 對我很有幫助,謝謝。

我看到這兩個選項:

 // your data let user = { name: 'pete', highscore: 12345 }; let game = { status: 'active', last_login: '1970-01-01' } // copy properties to an empty object. if there are properties of the same name on the same level the last value will overwrite any previous values let methodA = Object.assign({}, user, game); console.log(methodA); // thats simple, just an object with two properties each containing the original objects let methodB = { user: user, game: game }; console.log(methodB);

編輯:
您可以編寫自己的合並 function,它會在重復名稱上引發錯誤,或者通過為變量名稱添加前綴來修復命名。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM