从我的表angularjs得到amout列的总和

时间:2017-01-20 10:07:52

标签: asp.net angularjs web-services row totals

我想获得angularjs

中的金额列总数
List<object> newobj = new List<object>();
        SqlCommand cmd = new SqlCommand("showprofinalinstexpensesonid", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Connection = con;
        SqlParameter[] param = {
            new SqlParameter("@from",from),
            new SqlParameter("@to",to),
            new SqlParameter("@trainer",trainer),
            new SqlParameter("@sonvinid",sonvinid),
            new SqlParameter("@button",button)
        };
        con.Open();
        cmd.Parameters.AddRange(param);
        SqlDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            newobj.Add(new {
                sonvinid = dr["sonvinid"],
                date = dr["date"],
                brandname = dr["brandname"],
                zone = dr["zone"],
                location = dr["location"],
                area = dr["area"],
                venuename = dr["venuename"],
                venue = dr["venue"],
                instructore = dr["instructore"],
                amount = dr["amount"]
            });
        }
        var json = js.Serialize(newobj);
        Context.Response.Write("{" + '"' + "info" + '"' + ":" + json + "}");
        con.Close();

这是我的网络服务我从这个网络服务的sql中获取数据并将数据存储在我的表中,

控制器的工作由angularJS

完成
$http.get('listservice.asmx/getdataindiv2', {
                    params: {
                        from: $scope.datefrm,
                        to: $scope.dateto,
                        trainer: $scope.tid,
                        sonvinid: $scope.sonviniid,
                        button: $scope.checkstatus
                    }
                })

这是我的控制器从这里我将数据从我的webservice传输到我的表

然后这段代码帮助我传输数据

$scope.tableindiv2 = response.data.info;

现在这就是我的表格外观

                         <table id="table" class="table table-bordered font" style="width: 100%; padding-top: 10px;">
                                <thead>
                                    <tr class="bg-primary textalign">
                                        <th>SonVin Id</th>
                                        <th>Date</th>
                                        <th>Brand Name</th>
                                        <th>Venue Name</th>
                                        <th>City</th>
                                        <th>Area</th>
                                        <th>Instructore</th>
                                        <th>Training no.</th>
                                        <th>Amount</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr ng-repeat="fdata in tableindiv2">
                                        <td>{{fdata.sonvinid}}</td>
                                        <td>{{fdata.date}}</td>
                                        <td>{{fdata.brandname}}</td>
                                        <td>{{fdata.venuename}}</td>
                                        <td>{{fdata.location}}</td>
                                        <td>{{fdata.area}}</td>
                                        <td>{{fdata.instructore}}</td>
                                        <td>{{fdata.trainingno}}</td>
                                        <td>{{fdata.amount}}</td>
                                    </tr>
                                </tbody>
                            </table>

现在我只想做我的专栏

<td>{{fdata.amount}}</td>

我尝试过做这样的事情

(response.data.info[0].amount)

但它只是获取第一行的数量

我需要做什么,我想要总金额列

1 个答案:

答案 0 :(得分:1)

您可以计算控制器中的总金额

var totalAmount = 0;  
$scope.tableindiv2.forEach(function(t) { 
  totalAmount += t.amount;
});
$scope.totalAmount = totalAmount;

并将其绑定到视图

{{totalAmount}}