我正在尝试迭代这样的hashmap:
的index.html
<div ng-app>
<div ng-controller="ClickToEditCtrl">
<p>Your Data:</p>
<ul ng-repeat="(name, person) in data">
name: {{name}}
--------------------------
age: {{person.age}}
hair: {person.hair}}
</ul>
</div>
</div>
在我的ClickToEditCtrl.js
中function ClickToEditCtrl($scope) {
$scope.data =[];
$scope.data["Mike"] = new person (11,"blonde");
$scope.data["Dan"] = new person (22, "redhead");
}
function person(age, hair){
this.age = age;
this.hair = hair;
}
不起作用..
我得到空名单。
我做错了什么?
谢谢!
答案 0 :(得分:4)
您正在初始化新数组而不是对象
它应该是$scope.data =[];
而不是ng-repeat
您最好将li
放在ul
上,而不是<ul>
<li ng-repeat="(name, person) in data">
name: {{name}}
--------------------------
age: {{person.age}}
hair: {{person.hair}}
</li>
</ul>
std::list<int> l;
l.push_back(4);
l.push_back(2);
l.push_back(1);
l.sort();