Новички Angularjs сделали небольшой футляр в свободное время.
Функция: Рассчитайте цену предметов для корзины для покупок и удалите предметы корзины для покупок.
Ниже приведен полный случай (JQuery и AngularJS должны быть введены сами)
<! Doctype html> <html ng-app = "myApp"> <head> <meta charset = "utf-8"> <title> unt out назван документ </title> <style> .cursors {cursor: pointer} </style> <script src = "js/jquery-1.1.1.js" src = "js/angular.min.js"> </script> <script> var a = angular.module ('myApp', []); // корзина покупок плюс A.Directive ('myAdds', funct This = thisAngular.foreach (scope.datalist, function (data.dex, array) {if (attr.items == data.items) {data.num = parseint (data.num) +1; scope.allprices (); A.Directive ('myminus', function () {return {link: function (scope, element, attr) {element.click (function () {var this = thisAngular.foreach (scope.datalist, function (data, index, array) {if (attr.items == data.items) {if (data.num <= 1) Продукт ')) {data.num = 0; $ (this) .siblings (' input '). val (0); scope.allprices (); scope. $ Apply (); // delete Array [index];; scope.datalist.splice (index, 1) $ (this) .parents ('tr'). remove ();}} else {data.num = parseint (data.num) -1;}; scope.allprices (); A.directive ('allorcan', function () {return function (scope, element, attr) {element.click (function () {var ischeck = $ (this) .find ('input'). prop ('cherced'); if (ischeck) {$ ('input [type = fackbox]'). prop ('cherced', true);} else {$ ('input = fackbox]'). Не ($ ('input = fackbox]'). eq (0)) ('проверено', false);} angular.foreach (scope.datalist, function (data, index, array) {data.bol = ischeck;}) scope.allprices (); scope. $ Apply ();})}}) // Один выбор A.Directive ('OneCheck', function () {reture Function, actrick, attrick, attrick, attrick, attrick, attrick, attrick, attrick) This = thisangular.foreach (scope.datalist, function (data, index, array) {if (attr.items == data.items) {var ischeck = $ (this) .prop ('checked'); data.bol = ischeck; scope.allprices (); scope. $ apply ();}})});}}) a.controller ('myangular', ['$ scope', '$ filter', функция ($ scope, $ filter) {$ scope. cart {bol: 'false', имя: «стиральная машина», num: '1', элементы: '0', oneprice: '900', цена: ''}, {bol: 'false', имя: «Водонагреватель», n um: '1', элементы: '1', oneprice: '110', цена: ''}, {bol: 'false', имя: Кондиционер ', num:' 1 ', элементы:' 2 ', oneprice:' 116 ', цена:' '}, {bol:' false ', имя:' холодильник ', num:' 1 ', элементы:' 3 ', oneprice:' 2087 ', цена:' '}, {bol:' false ', name:' induction Плита ', num:' 1 ', элементы:' 4 ', oneprice:' 135 ', цена:' '}, {bol:' false ', name:' Quilt ', num:' 1 ', элементы:' 5 ', OnePrice:' 50 ', Price:' '}, {bol:' false ', имя:' book ', num:' 1 ', элементы:' 6 ', oneprice:' 2 ', цена:' '}, {bol:' false ', name:' pen ', num:' 1 ':' 7 ', Oneprice:' ' 115 ', цена:' '}, {bol:' false ', name:' cup ', num:' 1 ', элементы:' 8 ', oneprice:' 12 ', цена:' '}, {bol:' false ', name:' book ', num:' 1 ', элементы:' 9 ', oneprice:' 5 ', цена:' ', num:' 1 ', элементы:' 9 ', Oneprice:' 5 ', цена:' '' }, {Bol: 'false', name: 'snum:' 1 ', пункты:' 10 ', oneprice:' 13 ', цена:' '}]; // Расчет общей цены $ scope.allprices = function () {$ scope.allprice = 0; angular.foreach ($ scope.datalist, function (data, index, array) {data.price = data.num*data.Oneprice; if (data.bol == true) {$ scope.allprice+= parseint (data.price); Цена $ scope.cartsort = function (arg) {angular.foreach ($ scope.datalist, function (data, index, array) {arguments.callee ['cartsort ('+arg+')'] =! Arguments.c ALLEE ['CartSort ('+arg+')'] $ scope.datalist = $ filter ('orderby') ($ scope.datalist, arg, arguments.callee ['cartsort ('+arg+')'])})}) </script> </head> <body ng-controller = "myangular"> <table> <tr> <td> <label all-orcan> <input type = "fackbox"> выберите All/Cancel All </label> </td> <td> name </td> <td> Количество </td> <td ng-click = 'cartsort (oneprice') '> in undiate </td> <td ng-click =' td> </td> ng-cartsort (oneprice ')'> ng-td> </td> </td> <td ng-click = 'td> ng-click =' td> </tr> <tr ng-repeat = "data in datalist"> <td> <input type = "fackbox" election elects = {{data.items}}> </td> <td ng-cloak> {{data.name}} </td> <td> <input type = "ng-cloak ng-model =" data ". items = "{{data.items}}"> <button My-ADDS = "{{data.Items}}" ng-class = "{cursors: true}">+</button> <button my-minus emits = "{{{items}}" ng-class = "{cursors: true}"> ng-cloak> {{data.oneprice}} </td> <td ng-cloak> {{data.price}} </td> </tr> </table> <div> Общая цена: {{allprices ()}} </div> </body> </html> <!-</script> alert (0).Эффект показан на рисунке:
Уважайте результаты труда. Пожалуйста, укажите источник при перепечатку (http://blog.csdn.net/sllailcp/article/details/47833315) ...