【问题标题】:get total of amout column from my table angularjs从我的表 angularjs 中获取总数列
【发布时间】:2017-06-05 06:48:24
【问题描述】:

我想获取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
                    }
                })

这是我的控制器,我正在将数据从我的网络服务传输到我的表

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

$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)

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

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

【问题讨论】:

    标签: asp.net angularjs web-services


    【解决方案1】:

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

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

    并将其绑定到视图中

    {{totalAmount}}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多