【发布时间】:2016-07-21 17:36:28
【问题描述】:
数字小部件可以在同一个仪表板上多次使用吗?
例如 我想显示每个团队成员的当前分数,每个团队成员一个小部件,带有一个向上/向下箭头,将当前分数与最后一个分数进行比较,如果分数上升,小部件背景为绿色,如果它下降,小部件背景为红色。
我的 .rb 文件从 excel 文件中传递数据。
每个小部件都显示正确的当前分数 每个小部件都显示正确的向上/向下箭头 尽管 .coffee 显示相反,但所有小部件都显示与我想要的相同但相反的颜色。
就好像循环在第一次`pass后停止检测背景应该是哪种颜色。
错误或错误代码? number4.coffee
class Dashing.Number4 extends Dashing.Widget
@accessor 'current', Dashing.AnimatedValue
@accessor 'difference', ->
if @get('last')
last = parseInt(@get('last'))
current = parseInt(@get('current'))
if last != 0
diff = Math.abs(Math.round((current - last) / last * 100))
"#{diff}%"
else
""
@accessor 'arrow', ->
if @get('last')
if parseInt(@get('current')) > parseInt(@get('last')) then 'fa fa-arrow-up' else 'fa fa-arrow-down'
constructor: ->
super
@onData(Dashing.lastEvents[@id]) if Dashing.lastEvents[@id]
onData: (data) ->
if parseInt(@get('current')) > parseInt(@get('last')) then $(@node).css('background-color', '#006600') else $(@node).css('background-color', '#660000')
number4.scss
//
// ----------------------------------------------------------------------------
// Mixins
// ----------------------------------------------------------------------------
@mixin transition($transition-property, $transition-time, $method) {
-webkit-transition: $transition-property $transition-time $method;
-moz-transition: $transition-property $transition-time $method;
-o-transition: $transition-property $transition-time $method;
transition: $transition-property $transition-time $method;
}
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$value-color: #fff;
$title-color: rgba(255, 255, 255, 0.7);
$moreinfo-color: rgba(255, 255, 255, 0.7);
// ----------------------------------------------------------------------------
// Widget-number styles
// ----------------------------------------------------------------------------
.widget-number4 {
.title {
color: $title-color;
font-size: 40px;
}
.value {
color: $value-color;
}
.change-rate {
font-weight: 500;
font-size: 30px;
color: $value-color;
}
.more-info {
color: $moreinfo-color;
font-size: 23px;
bottom: 40px;
}
.updated-at {
color: white;
font-size: 23px;
}
}
【问题讨论】:
-
所有缩进都丢失了,这对 CoffeeScript 尤其不利。
标签: css background coffeescript widget dashing