[英]Braces in angular.js
比方說,例如,你有一個帶有"father": {"name":"Bob"}
的.json文件"father": {"name":"Bob"}
和一個javascript文件,它從中獲取數據並將其存儲在一個名為family的數組中。
然后{{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 }}
輸出'鮑勃'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.