【问题标题】:How to get element from a scope json according value of another scope json in angular js?如何根据角度js中另一个范围json的值从范围json中获取元素?
【发布时间】:2015-02-20 06:49:57
【问题描述】:

我有两个简单的 json 范围变量。

我需要根据我的第二个 json 中的另一个对象值显示我的第一个 json 中的特定对象的值,

喜欢:

{{json1.json2.id}} 问题是角度认为 json2 是 json1 中的一个对象。我希望编译器获取 json2.id 的结果并将其存储到一个对象(比如 temp)并在 json1(json1.temp)中找到相应的对象值。

这是我试图实现的概念。

我试过: {{json1.[json2.id]}}

{{json1}}.{{json2.id}}

{{json1.(json2.id)}}

我希望有人能理解我想问的问题。

json 示例

json1 以前的练习计数:{ 1:0, 3:3, 6:4, 10:3, 11:2, 15:2, 18:4, 21:1, 23:5, 24:1, 25:7 }

json2 练习日志:
[{ 编号:7,
名称:“推”,
代表:“0”,
时间:1424177576006
}, {
编号:15,
名称:“跳跃”,
代表:“不适用”,
时间:1424177576002
}, {
编号:23,
名称:“拉”,
代表:“0”,
时间:1424177576001
}, {
编号:40,
名称:“十字架”,
代表:“4”,
时间:1424177576000
}]

我正在使用 ng-repeat 遍历 json2 每次迭代都给了我 练习日志:{ 编号:40, 名称:“十字架”, 代表:“0”, 时间:1424177627130 }

例如,我需要获取 json.exercise.id 的值 即当我得到exerciseLog.id为40时,我需要得到它对应的previousExerciseCount。

【问题讨论】:

  • 添加你的示例 json
  • 是的,添加一个 json 数组的示例以及您要获取的内容..

标签: json angularjs angularjs-scope


【解决方案1】:

在你的控制器中$scope.result=$scope.json1[json2.id];//JS 代码

在 HTML 中使用 {{result}} //HTML

【讨论】:

  • 我在 ng-repeat 中使用这个,我需要获取 json1.json2.id 的每个值。 //njan parayanath manasilayo?
猜你喜欢
  • 1970-01-01
  • 2019-03-12
  • 2015-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多