您的位置:首頁技術文章
文章詳情頁

angular.js - 怎么用Angularjs 來實現如圖

瀏覽:164日期:2024-10-13 18:48:21

問題描述

angular.js - 怎么用Angularjs 來實現如圖

每一行作為一個訂單商品詳情選擇商品填充商品名稱,價格數量默認為1,價格和數量可以手動修改,總價不能修改 總價=數量*單價;

怎么綁定這個每一行的model啊

問題解答

回答1:

寫了一個sample做參考:

<body ng-app='orderSum'> <table ng-controller='orderController'><thead> <tr><th>序號</th><th>數量</th><th>單價</th><th>總價</th> </tr></thead><tbody ng-repeat='order in orders track by $index'> <tr><td>{{ $index+1 }}</td><td><input ng-model='order.count'></td><td><input ng-model='order.price'></td><td><input readonly='true' value='{{ order.count * order.price }}'></td> </tr></tbody> </table> <script> var myApp = angular.module('orderSum',[]); myApp.controller('orderController',[’$scope’,function($scope){$scope.orders=[];$scope.orders.length=10; }]); </script></body>回答2:

ng-repeat + array.push({id:1,name:’’,price:0,num:0})

ng-repeat=’x in array’

ng-model=’x.num’

ng-model=’x.price’

ng-bind=’x.num * x.price’

回答3:

ngRepeat

相關文章:
国产综合久久一区二区三区