javascript - 我想将存储在 JS 文件中的 JSON 变量触发到 HTML 文件中并遍历内容
问题描述
我遇到了一个问题,我将一些 JSON 数据存储在函数中定义的变量中。因此,要访问 JSON 数据,我首先需要进行函数调用。我的功能如下:
viewDeposits: function() {
var deposits = [];
App.contracts.BOKCoin.deployed().then(function(instance) {
bokcoinInstance = instance;
return bokcoinInstance.depositCount();
}).then(async function(depositCount) {
var count = depositCount.toNumber();
console.log(count);
for(var i=1; i<=count; i++) {
var x = await bokcoinInstance.deposits(i);
deposits.push(x);
}
console.log(deposits);
//send deposits to an html as an id
$('#deposits').html(deposits);
return deposits;
});
}
接下来,我想调用此函数并将其存储在 .HTML 文件中的变量中并循环遍历其内容。我能够将返回对象存储到变量中。
任何帮助将不胜感激。谢谢!
解决方案
推荐阅读
- r - 在 for 循环中,如何在“starts_with”引号内插入变量 i?
- websphere - 服务人员仅请求一次
- php - 如何使用 PHP 获取数组中的第一个唯一数字?
- c++ - C++ 结构的多重定义
- javascript - 你能解释一下为什么不需要在 promise 函数中输入值吗?
- python - 在 Python 中更改二维列表时出现奇怪的错误
- node.js - 从单独的第三方节点模块运行 Sequelize 迁移文件?
- flutter - Flutter:如何在聊天消息中制作电报类型气泡
- haskell - Haskell:了解自定义数据类型
- android - OkHttp3 HttpLoggingInterceptor 日志正文没有记录头