繁体   English   中英

浏览器中的 console.log 时未定义

[英]Undefined when console.log in the browser

代码如下:

let smartContractState = await zilliqa.blockchain.getSmartContractState(contractAddress);

let users_map = smartContractState.result.users; //users is a mapping as users[getAddress]=name

到目前为止,一切正常,因为我可以通过console.log(users_map)看到结果;

0x502a2dcaec7ce8a4790141e4fe4753e7edb6381a: "name" 0x812e4a8ec02a01a398141a6546822b1ed0d9acbf: "Naveen" 0xdfe5c37484fa6b83bac3e0673671cb19577c7729: "world" 0xfff4903b3b5739d5d79f73286d05db82677a29e6: "kumar"


但是当我这样做时:

let username = users_map[getAddress] ;//getAddress : is input by the user. 

其中 getAddress = 0x502a2dcaec7ce8a4790141e4fe4753e7edb6381a

并使用console.log(username); 它说undefined


I am providing the link for reference: https://devex.zilliqa.com/address/0x25af495166897a7b1c095f8c3af730446d79c142?network=https://dev-api.zilliqa.com Now you can check the state by going to the state section. getSmartContractState也是在 zilliqa.js 库中定义的方法。 任何人都可以帮忙吗?

smartContractState.result.user 不是一个数组,所以你不能 select 基于键( users_map[getAddress] )。 我的想法是使用for循环并检查是否匹配getAddress。

我的感觉是 getAddress 没有您期望的价值。 可能未定义,rest 看起来不错,所以我敢打赌这是你的问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM