【问题标题】:Add JSON Objects in AngularJS在 AngularJS 中添加 JSON 对象
【发布时间】:2014-06-25 03:13:22
【问题描述】:

所以我正在使用 AngularJS 提取一些 JSON

$http.get('/balance').then(function (response) {
  $scope.balance = response.data;
});

response.data 就是这个

{
  "pending": [{
    "amount": 16,
    "currency": "usd"
  }],
  "available": [{
    "amount": 20,
    "currency": "usd"
  }],
  "livemode": false,
  "object": "balance"
}

如何将两个“数量”加在一起并将它们设置为等于 Angular 中的一个变量?所以对于这个变量应该设置为16+20?

【问题讨论】:

  • 待处理数组和可用数组的长度为0,是固定的还是可以增长的?
  • @user3161730,将你的 JSON 解析成 JS 字典,parseInt() 数量,然后添加它们。

标签: javascript json angularjs http variables


【解决方案1】:

$scope.newProp = response.data.pending[0].amount + response.data.available[0].amount;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-27
    • 2015-07-20
    • 2016-12-27
    • 2016-06-29
    • 2018-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多