javascript - when checkbox = true -
i have been trying work out problem cant work out do.
my jsfiddle has dropmenu building level. each building level has value. have total value working, need have destroyed total. have added checkbox use if destroyed, cant work out how subtotal. did think of ng-if
cant work how use need, welcome help. need subtotalop equal op when checked true, can add armour destroyed separately total
var appbubble = angular.module('myexample', []); function myctrl($scope) { $scope.myoptionsop = [{ "armour": 1000, "label": "1" }, { "armour": 2000, "label": "2" }, { "armour": 4000, "label": "3" }, { "armour": 8000, "label": "4" }, { "armour": 16000, "label": "5" }, { "armour": 32000, "label": "6" }, { "armour": 64000, "label": "7" }, { "armour": 750000, "label": "8" }]; $scope.myoptionswh = [{ "armour": 100, "label": "1" }, { "armour": 600, "label": "2" }, { "armour": 1100, "label": "3" }, { "armour": 1600, "label": "4" }, { "armour": 2100, "label": "5" }, { "armour": 2600, "label": "6" }, { "armour": 3100, "label": "7" }, { "armour": 3600, "label": "8" }, { "armour": 4100, "label": "9" }, { "armour": 4600, "label": "10" }, { "armour": 5100, "label": "11" }, { "armour": 9277, "label": "12" }, { "armour": 17280, "label": "13" }, { "armour": 415000, "label": "14" }]; $scope.myoptionslp = [{ "armour": 450, "label": "1" }, { "armour": 788, "label": "2" }, { "armour": 1378, "label": "3" }, { "armour": 2412, "label": "4" }, { "armour": 4221, "label": "5" }]; $scope.myoptionssy = [{ "armour": 2000, "label": "1" }, { "armour": 4000, "label": "2" }, { "armour": 6000, "label": "3" }]; $scope.myoptionsdk = [{ "armour": 550, "label": "1" }, { "armour": 1200, "label": "2" }, { "armour": 1850, "label": "3" }, { "armour": 2500, "label": "4" }, { "armour": 3150, "label": "5" }, { "armour": 3800, "label": "6" }, { "armour": 4450, "label": "7" }, { "armour": 5100, "label": "8" }, { "armour": 5750, "label": "9" }, { "armour": 6400, "label": "10" }, { "armour": 7050, "label": "11" }, { "armour": 9150, "label": "12" }]; };
table, th, tr, td, p { font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; }
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <table border="1" ng-app="myexample" ng-controller="myctrl"> <tr> <td align=middle>building</td> <td align=left>level</td> <td align=middle>armour</td> <td align=left>destroyed</td> <tr> <td align=left width=100>outpost:</td> <td> <select style="width: 40px" ng-model="op" ng-options="value.armour value.label value in myoptionsop"></select> </td> <td align=left width=200>base armour: {{op}}</td> <td align=middle width=25> <input type="checkbox" ng-model="subtotalop"> </td> <tr> <td align=left width=100>warehouse:</td> <td> <select style="width: 40px" ng-model="wh1" ng-options="value.armour value.label value in myoptionswh"></select> </td> <td align=left width=200>base armour: {{wh1}}</td> <td align=middle width=25> <input type="checkbox" ng-model="subtotalwh1"> </td> <tr> <td colspan="4" align=left width=300> <br/> <br/><b>total of destroyed buildings: {{subtotalop+subtotalwh1}}</b> </td> <tr> <td colspan="4" align=left width=300> <br/><b>total of buildings: {{op+wh1}}</b> </td> </table>
updated:
i believe need:
{{(subtotalop === true ? op : 0) + (subtotalwh1 === true ? wh1 : 0)}}
actually, not approach, should logic in javascript. anyway, hope can sort problem.
checked new demo: https://jsfiddle.net/dltecsbj/10/
Comments
Post a Comment