【问题标题】:Push Checked Object in new array Angular js [closed]在新数组Angular js中推送检查对象[关闭]
【发布时间】:2017-02-09 13:48:14
【问题描述】:

我想将已检查的对象推送到新数组中并计算总价的总和/计数,我的角度/HTML 代码是:

<div class="panel panel-default" ng-repeat="daysheet in daysheets">

<div class="panel-heading">
    <h1 class="panel-title">{{daysheet.charge_client_name}}</h1>
</div>
<div class="panel-body">
    <form class="form_{{daysheet.id}}">

        <table class="table">
            <thead>
                <tr>
                    <th>Qty</th>
                    <th>Rate</th>
                    <th>Total</th>
                    <th>Invoice</th>
                </tr>
            </thead>

            <tbody>
                <tr ng-repeat="jobd in daysheet.job_details">
                    <td style="width: 70px">
                        <input type="text" name="qty[]" value="{{jobd.product_quantity}}" class="form-control ">
                    </td>
                    <td style="width: 80px">
                        <input type="text" value="{{jobd.job_product_rate}}" name="rate[]" class="form-control " disabled>
                    </td>
                    <td>
                        <input type="text" value="{{jobd.job_product_total_rate}}" name="total[]" ng-model="total" class="form-control total_count">
                    </td>
                    <td> //checkbox when user checked show this object amount and push value in new array 
                        <input type="checkbox" name="send_in[]" class="invoice_s_{{daysheet.id}}"  ng-model="selectedjob">
                    </td>
                </tr>
                <tr>
                    <td colspan="13">
                        <p class="pull-right "> Selected joblines Total <u>// select checkbox  amount(job_product_total_rate) / sum of all selected checkbox total amount(job_product_total_rate)  goes here</u>
                        </p>

                        <p class="pull-right "> Total Amount <u class="tot_amt">//total amount goes here</u>
                        </p>

                    </td>

                </tr>

            </tbody>

        </table>
    </form>
</div>

和 API 响应是:

[  
  {  
  "id":"2",
  "charge_client_name":"Ridgeway Bank",
  "job_details":[  
     {  

        "job_id":"4",
        "product_quantity":"55",
        "job_product_rate":"120",
        "job_product_total_rate":"6600",
        "distance":"200"
     },
     {  
        "job_id":"2",            
        "product_quantity":"55",           
        "job_product_rate":"120",
        "job_product_total_rate":"6600",
        "distance":"12"
     }
  ]
 },
 {  
  "id":"1",
  "charge_client_name":"Woolworths Market",
  "job_details":[  
     {              
        "job_id":"1",
        "product_quantity":"1200",
        "job_product_rate":"1200",
        "job_product_total_rate":"1440000",
        "distance":"100"
      }
   ]
 }]

我想在其中显示所有对象的所有金额/总量,例如 { job_product_total_rate } 的所有总和,当我们单击/选中复选框时,新数组中的推送对象值。 提前谢谢你

【问题讨论】:

    标签: angularjs arrays html


    【解决方案1】:

    这是您的示例: https://jsfiddle.net/e9ps7oa7/

    您可以使用checklist-model 创建带有复选框的列表。

    $scope.getTotalAmount函数是计算数组中属性的总和 并且您可以在daysheet.selected 数组中找到所有选中的job_details

    【讨论】:

    • 谢谢你我想要的工作......
    猜你喜欢
    • 1970-01-01
    • 2021-07-06
    • 2021-07-19
    • 2020-10-11
    • 2017-10-25
    • 1970-01-01
    • 2018-10-28
    • 1970-01-01
    • 2019-05-09
    相关资源
    最近更新 更多