怎么用Angularjs 来实现如图

clipboard.png

每一行作为一个订单商品详情
选择商品填充商品名称,价格
数量默认为1,价格和数量可以手动修改,总价不能修改 总价=数量*单价;

怎么绑定这个每一行的model啊

阅读 3.5k
3 个回答

写了一个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>

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'

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进