好的,试着做我应该做的简单的事情,我需要使用ng-重复和连接数组。完全不明白为什么这不管用。它非常适合基于数字的数组键,但不适合文本字符。
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/
我在这里做错什么了?我漏掉了什么明显的东西吗?
谢谢你们!
发布于 2014-11-06 14:15:58
在JavaScript中,我们没有关联数组--我们有对象:
更新小提琴:http://jsfiddle.net/edut808r/
angular.module('MyApp', []).filter('removeAdam', function() {
})
.controller('HelloCntl', function($scope) {
$scope.friends = {
asdf:'John',
dkfls: 'Mary',
aksnd: 'Mike',
alncjd: 'Adam',
skdnc: 'Julie'
}
});发布于 2014-11-06 15:02:33
不要使用关联数组!
http://andrewdupont.net/2006/05/18/javascript-associative-arrays-considered-harmful/
2不使用关联数组的主要原因
http://jsfiddle.net/3kppwhh6/1/
// using array
var friendsArr = [];
friendsArr['one']='one';
friendsArr['two']= 'two';
friendsArr.length; // 0
Object.keys(friendsArr).length; //2
//Using object
var friendsObj = {};
friendsObj['one'] ='one';
friendsObj['two'] = 'two';
Object.keys(friendsObj).length; //2https://stackoverflow.com/questions/26781498
复制相似问题