0

我在 AngularJs 中使用 linq.js,我想在 linq.js 中用两位小数对整列值求和。

请看下面的代码。

var app = angular.module('testApp', ['angular.filter', 'angular-linq', 'ngSelect2']);
app.controller('testController', function ($scope, $http, $timeout, $q, $linq){
    $scope.Vendors = 
    [
      { VendorId:"VND001", VendorName:"Pharma Plus Pharmacy", Address:"Bahawalpur", InvoiceAmount:25000, PackingCharges:1500, FreightCharges:100, MiscCharges:4000, OtherCharges:2500, TradeDiscount:2500 },
      { VendorId:"VND002", VendorName:"Pakistan Pharma", Address:"Bahawalpur", InvoiceAmount:35000, PackingCharges:1200, FreightCharges:885, MiscCharges:1165, OtherCharges:4000, TradeDiscount:2100},
    ];    
    $scope.sumOfTotal = function(vendorId, filter){
       return $linq.Enumerable().From($scope.Vendors).Where
             (" w => w.VendorId == '"+ vendorId +"'").Select(" x =>"+whereFilter).Sum();
    }
  }
}

请查看完整的 HTML

 <table class="table table-striped table-bordered table-hover table-irshad">
     <thead>
            <tr>
                <th> Vendor Id</th>
                <th> Vendor Name</th>
                <th> Total Amount</th>
                <th> Freight Charges</th>
                <th> Packing Charges</th>
                <th> Misc Charges</th>
                <th> Other Charges</th>
           </tr>
     </thead>
     <tbody>
           <tr ng-repeat="v in Vendors">
                <td> {{ v.VendorId }}</td>
                <td> {{ v.VendorName }}</td>
                <td> {{ v.InvoiceAmount }}</td>
                <td> {{ v.FerightCharges }}</td>
                <td> {{ v.PackingCharges }}</td>
                <td> {{ v.MiscCharges }}</td>
                <td> {{ v.OtherCharges }}</td>
           </tr>
            <tr>
                <td colspan="2"> Total Pendings:</td>
                <td> {{ sumOfTotal(v.VendorId, 'x.InvoiceAmount') }}</td>
                <td> {{ sumOfTotal(v.VendorId, 'x.FerightCharges') }}</td>
                <td> {{ sumOfTotal(v.VendorId, 'x.PackingCharges') }}</td>
                <td> {{ sumOfTotal(v.VendorId, 'x.MiscCharges') }}</td>
                <td> {{ sumOfTotal(v.VendorId, 'x.OtherCharges') }}</td>
           </tr>
     </tbody>

</table>
4

0 回答 0