[英]display specific data called from api in javascript
this is going to be a really easy question, but quite frankly I can't word it well enough to discover the answer on my own.这将是一个非常简单的问题,但坦率地说,我无法用自己的方式找到答案。 I should be able to roll forward with an answer.我应该能够回答。
client.getWalletBalance({coin: 'ETH'})
.then(result => {
console.log(result.ETH.available_balance);
var availableBal = result;
})
.catch(err => {
console.error(err);
});
later in the code:
'wallet balance:' + availableBal + ' ETH'
TypeError: Cannot read property 'available_balance' of undefined TypeError:无法读取未定义的属性“available_balance”
and和
ReferenceError: availableBal is not defined ReferenceError: availableBal 未定义
Here's the Response Example这是响应示例
{
"ret_code": 0,
"ret_msg": "OK",
"ext_code": "",
"ext_info": "",
"result": {
"ETH": {
"equity": 1002, //equity = wallet_balance + unrealised_pnl
"available_balance": 999.99987471, //available_balance
"used_margin": 0.00012529, //used_margin = wallet_balance - available_balance
"order_margin": 0.00012529, //Used margin by order
"position_margin": 0, //position margin
"occ_closing_fee": 0, //position closing fee
"occ_funding_fee": 0, //funding fee
"wallet_balance": 1000, //wallet balance. When in Cross Margin mod, the number minus your unclosed loss is your real wallet balance.
"realised_pnl": 0, //daily realized profit and loss
"unrealised_pnl": 2, //unrealised profit and loss
"cum_realised_pnl": 0, //total relised profit and loss
"given_cash": 0, //given_cash
"service_cash": 0 //service_cash
}
},
"time_now": "1578284274.816029",
"rate_limit_status": 98,
"rate_limit_reset_ms": 1580885703683,
"rate_limit": 100
}
essentially im trying to pick the certain part of the response, set it as a variable and reuse it later on本质上,我试图选择响应的特定部分,将其设置为变量并稍后重用
You've missing a .result
there.你在那里错过了一个.result
。
result.result.ETH.available_balance
. result.result.ETH.available_balance
。
You may got confused because you variable is also named result
.您可能会感到困惑,因为您的变量也被命名为result
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.