国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

AngularJS ng-repeat遍歷輸出的用法

2024-05-06 15:15:44
字體:
來源:轉載
供稿:網友

AngularJS  ng-repeat遍歷輸出的用法,最近需要用,就順便發到隨筆上了

<!doctype html><html><head>  <meta charset="utf-8">  <title>ng-repeat directive</title></head><body ng-app="myApp"><table ng-controller="CartController">  <caption>我的購物車</caption>  <tr>    <th>序號</th>    <th>商品</th>    <th>單價</th>    <th>數量</th>    <th>金額</th>    <th>操作</th>  </tr>  <tr ng-repeat="item in items">    <td>{{$index + 1}}</td>    <td>{{item.name}}</td>    <td>{{item.price | currency}}</td>    <td><input ng-model="item.quantity"></td>    <td>{{item.quantity * item.price | currency}}</td>    <td>      <button ng-click="remove($index)">Remove</button>    </td>  </tr></table><script src="js/angular-1.3.0.14/angular.min.js"></script><script>  var app = angular.module('myApp', []);  app.controller('CartController',function($scope){    $scope.items = [      {name: "蘋果 iPhone7", quantity: 1, price: 5088.00},      {name: "榮耀Magic", quantity: 1, price: 3699.00},      {name: "vivo X9", quantity: 2, price: 2798.00}    ];    //$index包含了ng-repeat過程中的循環計數    $scope.remove = function (index) {      $scope.items.splice(index, 1);    }  })</script></body></html>

ng-repeat指令生命在需要循環內容的元素上,items和控制器上的變量名對應,item是為數組中單個對象起的別名。

$index可以返回當前引用對象的序號,從0開始,另外還有$first、$middle、$last可以返回布爾值,用于告訴你

當前元素是否是集合中的第一個中間的最后一個元素。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持錯新站長站。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 岳阳县| 砀山县| 荔浦县| 黑水县| 莱西市| 扬州市| 红桥区| 台中市| 天祝| 静海县| 松原市| 舒城县| 松溪县| 通河县| 额敏县| 仁寿县| 蓬莱市| 偏关县| 勃利县| 博湖县| 宜春市| 喜德县| 靖宇县| 陆良县| 石柱| 兴城市| 河池市| 临江市| 江山市| 确山县| 南召县| 文成县| 呼和浩特市| 田阳县| 台北市| 牡丹江市| 芒康县| 沁阳市| 汶川县| 章丘市| 阿城市|