Angular ng-repeat 对象和数组遍历实例
直接上代码
<!DOCTYPEhtml>
<html>
<head>
<metaname="description"content="[Ngrepeatinobjandarr]">
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.14/angular.min.js"></script>
<metacharset="utf-8">
<title>JSBin</title>
</head>
<body>
<divng-app="myApp">
<divng-controller="testCtrl">{{test1}}
<div>
<labelfor=""ng-repeat="iteminlist1">{{item.id}}--{{item.value}}</label>
<p></p>
<labelfor=""ng-repeat="(key,value)inobj1">{{key}}--{{value}}</label>
<p>
</p>
对于obj遍历的话会根据key的首字母排序
<labelfor=""ng-repeat="(key,value)inobj2">
{{key}}--{{value.text}}--{{value.value}}
</label>
</div>
</div>
</div>
</body>
</html>
JS
varapp=angular.module(‘myApp‘,[]);
app.controller(‘testCtrl‘,function($scope){
$scope.test1=‘tt‘;
$scope.list1=[{
id:‘1‘,
value:‘seti‘
},{
id:‘2‘,
value:‘kuma‘
},{
id:‘3‘,
value:‘cent‘
}];
$scope.obj1={
‘1‘:‘seti‘,
‘2‘:‘kuma‘,
‘3‘:‘cent‘
};
$scope.obj2={
‘ins‘:{text:‘seti‘,value:‘s1‘},
‘abc‘:{text:‘kuma‘,value:‘s2‘},
‘coln‘:{text:‘cent‘,value:‘s3‘}
};
});
热门推荐
1 训练狗狗基础
2 怎么训练狗狗笑
3 怎么训练狗狗卧下
4 上海狗狗训练基地
5 训练狗狗排便
6 狗狗基础训练
8 如何训练狗狗装死
9 狗狗站姿训练
10 狗狗训练用品
11 训练狗狗吧
12 狗狗要怎么训练
13 怎么训练狗狗玩球
14 训练狗狗唤回
15 狗狗训练躺下
16 狗狗训练指令
17 狗狗的训练技巧
18 狗狗不好训练