[英]angular: accessing a JSON value using a variable key
I have a variable param
in scope as $scope.param
that is always either foo
or bar
. 我在范围内有一个变量
param
作为$scope.param
,它总是foo
或bar
。 I'm creating a table with rows defined by <tr ng-repeat="d in data">
. 我正在创建一个表,其中的行由
<tr ng-repeat="d in data">
。
When I have the following: <td>{{d.foo}}</td>
or <td>{{d.bar}}</td>
everything works and the data shows up fine. 当我有以下内容时:
<td>{{d.foo}}</td>
或<td>{{d.bar}}</td>
一切正常,数据显示正常。 However, when I have <td>{{d.param}}</td>
angular can't find anything and the cell is blank. 但是,当我有
<td>{{d.param}}</td>
angular时,找不到任何内容并且单元格为空。
In other words, I'm trying to access an object value using a variable as the key rather than the key itself. 换句话说,我试图使用变量作为键而不是键本身来访问对象值。 Any idea how to do this?
知道怎么做吗?
使用括号表示法:
{{d[param]}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.