例如,假设您有一个带"father": {"name":"Bob"}
的.json文件和一个从其中获取数据并将其存储在名为family的数组中的javascript文件。{{family.father.name}}
然后将在html页面上打印出父亲的名字。
是否可以做类似的事情:
在javascript文件中:
$scope.member = "father";
在index.html中:
{{family.{{member}}.name}}
// Is there some way to replace father with a variable
// from the javascript file? Just curious.
最佳答案
使用字典符号,是
var member = 'father'
family[member].name === family.father.name
或成角度
js:
$scope.member = 'father'
$scope.family = { 'father': { name : 'Bob' } }
的HTML:
{{ family[member].name }}
将输出“鲍勃”
关于javascript - Angular.js中的大括号,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19525126/