好吧,试着做我应该是一件简单的事情,我需要使用ng-repeat和assocative数组。完全失去了为什么这不起作用。它完全适用于基于数字的数组键,但不能使用文本字符。ng-repeat与关联数组
function HelloCntl($scope) {
$scope.friends = [];
$scope.friends[0] ='John',
$scope.friends[1]= 'Mary',
$scope.friends['aksnd']= 'Mike',
$scope.friends['alncjd']= 'Adam',
$scope.friends['skdnc']= 'Julie'
}
----
<div ng-controller="HelloCntl">
<ul>
<li ng-repeat="friend in friends">
<span>{{friend}}</span>
</li>
</ul>
</div>
我也放在一起,这是小提琴显示发生了什么 http://jsfiddle.net/b9g0x7cw/4/
我在做什么错在这里?我错过了明显的东西吗?
谢谢你们!
是的,我一直都知道,但从来没有真正钻研的差异,一些研究之后,我意识到,assocative阵列是一种没有没有(http://andrewdupont.net/2006/05/18/javascript-associative-arrays-considered-harmful /),并使用对象表示法代替。很高兴知道!我从来没有意识到关联数组的数组长度是0,这就是为什么当我大吼大叫时,角度看着我很奇怪。 – Justin 2014-11-06 14:40:56