当前位置: 动力学知识库 > 问答 > 编程问答 >

AngularJS : Resolving complex Json keys in views

问题描述:

I have a $scope variable scopeVar which contains a JSON Object. The JSON object has some complicated key names such as "onStatus[1]".

Is it possible to resolve such key names inside the view template so that I can use them like {{scopeVar.onStatus[1]}} or ng-bind="scopeVar.onStatus[1]" ?.

PS- I assume that using JSON keys in such a fashion is possible after reading this answer.However I am still skeptical regarding using symbols like '[' etc in key names as they may also be used to represent array elements.

网友答案:

If onStatus[1] is actually a property name and not the second element of the onStatus array you should use bracket notation to access the property:

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

or as the expression in ngBind:

ng-bind="scopeVar['onStatus[1]']"
网友答案:

Use it like this in the view it works for me.

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

Basically in the interpolation anything you put is treated as plain JS code so anything that works in the console of your browser will also work in the between the curly braces.

分享给朋友:
您可能感兴趣的文章:
随机阅读: