在angularJs中進行數(shù)據(jù)遍歷的2種方法
更新時間:2018年10月08日 14:32:35 作者:泠泠在路上
今天小編就為大家分享一篇在angularJs中進行數(shù)據(jù)遍歷的2種方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
2種方式分別為:
1、數(shù)組數(shù)據(jù)遍歷
2、對象數(shù)據(jù)遍歷
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="angular.min.js"></script>
</head>
<body>
<div ng-app="module" ng-controller="ctrl">
{{data}}
</div>
<script>
var m = angular.module('module', []);
m.controller('ctrl', ['$scope', function ($scope) {
$scope.data=[{name: '泠泠在路上', url: 'boke.com'},{name: '泠泠似水', url: 'zlm.com'}]
//數(shù)組數(shù)據(jù)遍歷
angular.forEach($scope.data, function (v, k) {
v.url = 'www.'+v.url;
console.log(v);//讀到所有的數(shù)組數(shù)據(jù)
console.log(k);//讀到所有的對象的下標
});
//對象數(shù)據(jù)遍歷
data ={name: '泠泠在路上', url: 'baidu.com'};
angular.forEach(data, function (v, k) {
v.url = 'www.'+v.url;
console.log(v);//得到對象的值,即泠泠在路上和baidu.com
console.log(k);//得到對象下標name和url
});
}]);
</script>
</body>
</html>
以上這篇在angularJs中進行數(shù)據(jù)遍歷的2種方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
AngularJs的UI組件ui-Bootstrap之Tooltip和Popover
這篇文章主要介紹了AngularJs的UI組件ui-Bootstrap之Tooltip和Popover,tooltip和popover是輕量的、可擴展的、用于提示的指令。具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-07-07
Angular6 Filter實現(xiàn)頁面搜索的示例代碼
這篇文章主要介紹了Angular6 Filter實現(xiàn)頁面搜索的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-12-12
Angular.js中window.onload(),$(document).ready()的寫法淺析
這篇文章主要介紹了Angular.js中window.onload(),$(document).ready()的寫法淺析,需要的朋友可以參考下2017-09-09
AngularJS中如何使用$http對MongoLab數(shù)據(jù)表進行增刪改查
這篇文章主要介紹了AngularJS中如何使用$http對MongoLab數(shù)據(jù)表進行增刪改查的相關資料,需要的朋友可以參考下2016-01-01

