Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AngularJS:在视图中解析复杂的Json键_Json_Angularjs_Ng Bind - Fatal编程技术网

AngularJS:在视图中解析复杂的Json键

AngularJS:在视图中解析复杂的Json键,json,angularjs,ng-bind,Json,Angularjs,Ng Bind,我有一个$scope变量scopeVar,它包含一个JSON对象。JSON对象有一些复杂的键名,例如“onStatus[1]” 是否可以在视图模板中解析这样的键名,以便像{{scopeVar.onStatus[1]}}或ng bind=“scopeVar.onStatus[1]”那样使用它们 PS-阅读本文后,我假设以这种方式使用JSON键是可能的。但是,我仍然怀疑在键名中使用“[”等符号,因为它们也可能用于表示数组元素。如果onStatus[1]实际上是一个属性名称,而不是onStatus数组

我有一个
$scope
变量
scopeVar
,它包含一个JSON对象。JSON对象有一些复杂的键名,例如
“onStatus[1]”

是否可以在视图模板中解析这样的键名,以便像
{{scopeVar.onStatus[1]}}
ng bind=“scopeVar.onStatus[1]”那样使用它们


PS-阅读本文后,我假设以这种方式使用JSON键是可能的。但是,我仍然怀疑在键名中使用“[”等符号,因为它们也可能用于表示数组元素。

如果
onStatus[1]
实际上是一个属性名称,而不是
onStatus
数组的第二个元素。您应该使用括号表示法访问属性:

{{ scopeVar['onStatus[1]'] }}
或作为
ngBind
中的表达式:

ng-bind="scopeVar['onStatus[1]']"

在视图中这样使用它对我有用

{{ scopeVar['onStatus[1]'] }}

基本上,在插值中,您输入的任何内容都被视为纯JS代码,因此在浏览器控制台中工作的任何内容都将在花括号之间工作。

so
onStatus[1]
实际上是属性的名称?它不是
onStatus
数组的第二个元素?是的。它是属性的名称。是的。它应该是这样工作的。实际上我尝试了这个解决方案,但将其用作
{scopeVar[onStatus[1]]}
。没有将键名作为字符串放在“..”内。感谢您的早期回复。