使用Coffeescript的汇总表?
我已经编写了一个汇总表,我正在尝试添加一个“总计”行,它将汇总三列。练习由许多问题组成,参与者可以增加、减少或维持一定的金额。列B总计显示初始值(滑块开始的位置)。C列显示参与者增加或减少的金额,最后一列显示产生的美元金额。(B+C) 下面是汇总表的一个示例 A列--B列--C列--D列 问题1 | 100$|+28$| 128$|使用Coffeescript的汇总表?,coffeescript,Coffeescript,我已经编写了一个汇总表,我正在尝试添加一个“总计”行,它将汇总三列。练习由许多问题组成,参与者可以增加、减少或维持一定的金额。列B总计显示初始值(滑块开始的位置)。C列显示参与者增加或减少的金额,最后一列显示产生的美元金额。(B+C) 下面是汇总表的一个示例 A列--B列--C列--D列 问题1 | 100$|+28$| 128$| 问题2 | 150美元|(10美元)| 140美元| 总计------250美元+18美元268美元| 到目前为止,我已经能够对B列和D列的总计进行编程,但我不知
问题2 | 150美元|(10美元)| 140美元|
总计------250美元+18美元268美元| 到目前为止,我已经能够对B列和D列的总计进行编程,但我不知道如何显示C列的总计
class window.CustomSimulator extends window.TaxSimulator
constructor: (@options = {}) ->
super
@updateTable()
update: ->
super
@updateTable()
updateTable: ->
self = this
$table = $('<table class="table table-condensed"><thead><tr><th>Category</th><th>Before</th><th>Your Choice</th><th>After</th></tr></table>')
$tbody = $('<tbody></tbody>')
before_total = 0
after_total = 0
@scope.find('.slider').each ->
$this = $(this)
$parents = $this.parents('tr')
category = $parents.find('.header').clone().children().remove().end().text().replace(/How would you adjust service levels and property tax funding for /, '').replace('?', '')
before = self.tipScaler($this, $this.data('initial'))
your_choice = $parents.find('.value').text()
after = $parents.find('.tip-content').text()
if $parents.find('.key').text() == 'Decrease:'
css_class = 'decrease'
your_choice = "(#{your_choice})"
else
css_class = 'increase'
$tr = $("""<tr><td>#{category}</td><td>#{before}</td><td class="table-#{css_class}">#{your_choice}</td><td>#{after}</td></tr>""")
$tbody.append($tr)
before_total += parseFloat(before.replace('$', ''))
after_total += parseFloat(after.replace('$', ''))
before_total = SimulatorHelper.number_to_currency(before_total, precision: 2, strip_insignificant_zeros: true)
after_total = SimulatorHelper.number_to_currency(after_total, precision: 2, strip_insignificant_zeros: true)
$("""<tfoot><tr><th>Totals</th><th>#{before_total}</th></th><th><th>#{after_total}</th></tr></tfoot>""").appendTo($table)
$table.append($tbody)
$('#summary-table').html($table)
class window.CustomSimulator扩展了window.TaxSimulator
构造函数:(@options={})->
超级的
@updateTable()
更新:->
超级的
@updateTable()
updateTable:->
self=这个
$table=$('CategoryBefore Your ChoiceAfter')
$t正文=$(“”)
前_总计=0
后加总=0
@查找('.slider')。每个->
$this=$(this)
$parents=$this.parents('tr'))
category=$parents.find('.header').clone().children().remove().end().text().replace(/您将如何调整服务级别和物业税资金/,'')。replace('?','')
before=self.tipScaler($this,$this.data('initial'))
您的选择=$parents.find('.value').text()
after=$parents.find('.tip content').text()
如果$parents.find('.key').text()=='减少:'
css_类=‘减少’
your_choice=“(#{your_choice})”
其他的
css_类=‘增加’
$tr=$(“{category}}{before}}{your_choice}}{after}”等)
$tbody.append($tr)
before_total+=parseFloat(before.replace(“$”,“))
after_total+=parseFloat(在.replace('$,'')之后)
before\u total=SimulatorHelper.number\u到\u currency(before\u total,精度:2,带0:true)
after\u total=SimulatorHelper.number\u到\u currency(after\u total,精度:2,strip\u不重要\u Zero:true)
$(“总计{u总计}{u总计}之前}{u总计}”之后。)。附录($table)
$table.append($tbody)
$('#汇总表').html($table)
我对这方面还不太熟悉,所以我不确定这是否是足够的信息
谢谢 你仍然对答案感兴趣吗?你仍然对答案感兴趣吗?