【发布时间】:2015-06-02 08:17:20
【问题描述】:
我想使用 ngRepeat 循环访问一些数据,并动态访问顶层或嵌套在几个级别下的数据。
但是,似乎我可以显示顶级属性,但在嵌套时却不行。
JS:
var mapping = [
{property:'a'}, // works
{property:'b.c1'}, // doesn't work
{property:'b.c2'} // doesnt work
];
var arr = {
a: 'text',
b: {
c1: 'text2',
c2: 'text3'
}
};
HTML:
<div ng-repeat="mappingItem in mapping">
<p>{{arr[mappingItem.property]}}</p>
</div>
【问题讨论】:
-
你试过了吗? var mapping = [ {property:'a'}, {property:'b['c1']'}, {property:'b.['c2']'} ];
-
@DivyaMV 刚试了没用
-
如果你使用 arr['b.c1'] 它不会工作,但如果你使用 arr['b'].c1 那么它工作
-
如果不能更改结构,这可能会有所帮助stackoverflow.com/questions/6906108/…
标签: javascript angularjs