Problème avec le cycle de demande d'API
2 réponses
- votes
-
- 2019-03-25
Lepremier élément renvoyé de https://api6.tzscan.io/v3/rolls_history/tz1nortrftucvakd1j58l32ehsvrqewjcenb? Number=1 est les données du dernier cycle.
html
<h1>Last Cycle</h1> <div id="cycle"></div> <div id="rollCount"></div> <div id="rollTotal"></div>
JavaScript
const url = 'https://api6.tzscan.io/v3/rolls_history/tz1NortRftucvAkD1J58L32EhSVrQEWJCEnB?number=1&page=0'; const cycleEl = document.getElementById('cycle') const rollCountEl = document.getElementById('rollCount') const rollTotalEl = document.getElementById('rollTotal') fetch(url) .then(resp => resp.json()) .then(([lastCycle]) => { cycleEl.innerText = lastCycle.cycle rollCountEl.innerText = lastCycle.roll_count rollTotalEl.innerText = lastCycle.roll_total }) .catch(console.log);
The first element returned from https://api6.tzscan.io/v3/rolls_history/tz1NortRftucvAkD1J58L32EhSVrQEWJCEnB?number=1 is the data from the latest cycle.
HTML
<h1>Last Cycle</h1> <div id="cycle"></div> <div id="rollCount"></div> <div id="rollTotal"></div>
JavaScript
const url = 'https://api6.tzscan.io/v3/rolls_history/tz1NortRftucvAkD1J58L32EhSVrQEWJCEnB?number=1&page=0'; const cycleEl = document.getElementById('cycle') const rollCountEl = document.getElementById('rollCount') const rollTotalEl = document.getElementById('rollTotal') fetch(url) .then(resp => resp.json()) .then(([lastCycle]) => { cycleEl.innerText = lastCycle.cycle rollCountEl.innerText = lastCycle.roll_count rollTotalEl.innerText = lastCycle.roll_total }) .catch(console.log);
-
- 2019-03-25
Ceciestplus d'une questionjavascriptpuis une question de Tezos,mais detoutefaçon;
const ul2 = document.getElementById('Cycle'); const url2 = 'https://api6.tzscan.io/v3/rolls_history/tz1NortRftucvAkD1J58L32EhSVrQEWJCEnB?number=1&page=0'; fetch(url2) .then((resp) => resp.json()) .then(function(data){ if (data.length > 0) { let span = document.createElement('span'); span.innerHTML = `${data[0].cycle}`; ul2.appendChild(span) } }) .catch(function(error) { console.log(error); });
Si vous avez déjàplusieurs éléments dans lamatrice de données retournée,vous deveztrier lamatrice avant de choisir l'élément correct.
This is more of a Javascript question then a Tezos question, but anyway;
const ul2 = document.getElementById('Cycle'); const url2 = 'https://api6.tzscan.io/v3/rolls_history/tz1NortRftucvAkD1J58L32EhSVrQEWJCEnB?number=1&page=0'; fetch(url2) .then((resp) => resp.json()) .then(function(data){ if (data.length > 0) { let span = document.createElement('span'); span.innerHTML = `${data[0].cycle}`; ul2.appendChild(span) } }) .catch(function(error) { console.log(error); });
If you ever get multiple items in the returned data array you need to sort the array before picking the correct element.
-
Mercipour votre aidemais çane marchepas!J'essaietoute lafaçonpossible!Pensez-vous queje devraismieux demander que sur lejavascript Stackexchange?Thanks for you help but it doesn't work ! I try all the way possible ! Do you think I should better ask that on the JavaScript stackexchange ?
- 0
- 2019-03-25
- Lexxor
-
Peut-être quej'aimal compris ce que vousessayez defaire.Avez-vousessayé Richards répondre ci-dessus?Perhaps I misunderstand what you are trying to do. Did you try Richards answer above?
- 0
- 2019-03-26
- asbjornenge
J'ai unproblèmepour demander lenuméro de cycle de API .Jene comprendspas comment utiliser la cartepour obtenir les données du dernier cycle uniquement.
https://codepen.io/anon/pen/amxeyj