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

首頁 > 編程 > JavaScript > 正文

AngularJS ng-repeat遍歷輸出的用法

2019-11-19 16:18:24
字體:
供稿:網(wǎng)友

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

<!doctype html><html><head>  <meta charset="utf-8">  <title>ng-repeat directive</title></head><body ng-app="myApp"><table ng-controller="CartController">  <caption>我的購(gòu)物車</caption>  <tr>    <th>序號(hào)</th>    <th>商品</th>    <th>單價(jià)</th>    <th>數(shù)量</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過程中的循環(huán)計(jì)數(shù)    $scope.remove = function (index) {      $scope.items.splice(index, 1);    }  })</script></body></html>

ng-repeat指令生命在需要循環(huán)內(nèi)容的元素上,items和控制器上的變量名對(duì)應(yīng),item是為數(shù)組中單個(gè)對(duì)象起的別名。

$index可以返回當(dāng)前引用對(duì)象的序號(hào),從0開始,另外還有$first、$middle、$last可以返回布爾值,用于告訴你

當(dāng)前元素是否是集合中的第一個(gè)中間的最后一個(gè)元素。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 雅安市| 合阳县| 荃湾区| 洮南市| 黎平县| 呼玛县| 米脂县| 柘荣县| 合作市| 高淳县| 英山县| 墨竹工卡县| 彰化市| 桓台县| 麻城市| 漳浦县| 东乌珠穆沁旗| 永平县| 福泉市| 田阳县| 汉川市| 吉安市| 浦东新区| 宜阳县| 长治市| 九龙城区| 波密县| 玉环县| 信宜市| 顺平县| 福清市| 定日县| 天峻县| 库伦旗| 连云港市| 新建县| 双柏县| 奉节县| 沙雅县| 龙海市| 苏州市|