将结果值传输到新选项卡

Transferring the result values to the new tab

我使用带有 BitcoreJavaScript 的比特币应用程序并使用下面提供的函数获取控制台日志-

   function getTransactions() {

                var result = {};
                var address = $('#address').find(":selected").text();
                var explorers = require('bitcore-explorers');
                var client = new explorers.Insight('testnet');

                client.getUnspentUtxos(address, function (err, transactions) {
                    result.transactions = transactions;

                    var len = result.transactions.length;

                    for (i = 0; i < len; i++) { 

                        console.log(result.transactions[i].address.toString());
                        console.log(result.transactions[i].amount);
                    }

                    setConsoleData('', result);
                });
            };

下面提供的控制台打印,

{
      "transactions": [
        {
          "address": "mtfXS7TGSDVMyxhby4YwvACqACLwxdthxQ",
          "txid": "5d1d86257096902f53762aaf2b7d43c44bf1997523dc8878d1157349dda5846f",
          "vout": 1,
          "scriptPubKey": "76a9149038a0390fea805ca27f700f14d329a4fb7dbf4788ac",
          "amount": 0.001
        },
        {
          "address": "mtfXS7TGSDVMyxhby4YwvACqACLwxdthxQ",
          "txid": "c3f6d0129eea1dc89fcb35e1c36d3537ebf291a887f31c75b590b2ebe7d8ba1c",
          "vout": 1,
          "scriptPubKey": "76a9149038a0390fea805ca27f700f14d329a4fb7dbf4788ac",
          "amount": 0.001
        },
        {
          "address": "mtfXS7TGSDVMyxhby4YwvACqACLwxdthxQ",
          "txid": "b04229c1052e962ec2fc2cc1b924c1cd67c30864c45e314d7dc8ef45f614e7ec",
          "vout": 1,
          "scriptPubKey": "76a9149038a0390fea805ca27f700f14d329a4fb7dbf4788ac",
          "amount": 0.001
        },
        {
          "address": "mtfXS7TGSDVMyxhby4YwvACqACLwxdthxQ",
          "txid": "d5190362895dc4eb37e7f7ba68889f402771ce3fa46704a027101d94c7ab87d5",
          "vout": 1,
          "scriptPubKey": "76a9149038a0390fea805ca27f700f14d329a4fb7dbf4788ac",
          "amount": 0.001
        }
      ]
    }

对于 console.log(result.transactions[i].amount);,我得到 undefined 打印输出。当我尝试使用 amount.toString() 时,出现错误,因为它试图获取 undefinedtoString()

当我在 setConsoleData 之后使用代码 window.open('transactions.html?result='+ result); 时,我可以使用 URL

打开一个新标签

file:///Users/Myelan/Documents/Projects/Wallet-App-JS/transactions.html?result=[object%20Object]

我需要在新的 HTML 选项卡中使用它们的 addresses, the amount and the txid 进行所有交易,我需要知道如何将 result 值传递到新选项卡。

我怎样才能做到这一点?

Note

当我编写代码 result = JSON.parse(result); 时,我在控制台中得到以下打印信息,

使用 result = JSON.parse(result); 将 json 响应字符串解析为 JSON 对象。

function getTransactions() {
    var result = {};
    var address = $('#address').find(":selected").text();
    var explorers = require('bitcore-explorers');
    var client = new explorers.Insight('testnet');

    client.getUnspentUtxos(address, function (err, transactions) {
        result.transactions = JSON.parse(transactions);
        var len = result.transactions.length;

        for (i = 0; i < len; i++) { 

            console.log(result.transactions[i].address.toString());
            console.log(result.transactions[i].amount);
        }

        setConsoleData('', result);
    });
};