国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 宜兴市| 修武县| 扎囊县| 如东县| 绍兴县| 三明市| 桐庐县| 霍林郭勒市| 临汾市| 怀化市| 武隆县| 彭山县| 汝南县| 内黄县| 德钦县| 蒲城县| 达孜县| 沽源县| 临猗县| 都安| 紫金县| 公主岭市| 瓮安县| 运城市| 小金县| 灵台县| 连南| 屯留县| 科技| 淮南市| 弋阳县| 古田县| 侯马市| 益阳市| 武夷山市| 平远县| 广丰县| 乐昌市| 公安县| 公安县| 洪洞县|