简体   繁体   English

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

[英]Undefined when console.log in the browser

The code is as follows:代码如下:

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

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

Till this point everything works fine as I can see the result by console.log(users_map) ;到目前为止,一切正常,因为我可以通过console.log(users_map)看到结果;

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


But when I do this:但是当我这样做时:

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

where getAddress = 0x502a2dcaec7ce8a4790141e4fe4753e7edb6381a其中 getAddress = 0x502a2dcaec7ce8a4790141e4fe4753e7edb6381a

and print it using console.log(username);并使用console.log(username); it says undefined它说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. 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. Also getSmartContractState is a method defined in the zilliqa.js library. getSmartContractState也是在 zilliqa.js 库中定义的方法。 Can anyone help?任何人都可以帮忙吗?

smartContractState.result.user is not an array so you can't select based on key ( users_map[getAddress] ). smartContractState.result.user 不是一个数组,所以你不能 select 基于键( users_map[getAddress] )。 My thought is to use a for loop and check if if matches getAddress.我的想法是使用for循环并检查是否匹配getAddress。

My feeling is that getAddress does not have the value you're expecting to have.我的感觉是 getAddress 没有您期望的价值。 Probably undefined, the rest looks good so I bet that's your problem可能未定义,rest 看起来不错,所以我敢打赌这是你的问题

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

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