数字小部件是否可以在同一仪表板上多次使用?
例如,我想要显示每个团队成员的当前分数,每个团队成员一个小工具,用向上/向下箭头比较当前分数和最后一个分数,如果分数是向上的,则小工具背景是绿色的,如果是向下的,则小工具背景是红色的。
我的.rb文件传递来自excel文件的数据。
每个小部件都显示正确的当前分数,每个小部件都显示正确的向上/向下箭头,所有小部件都显示与我想要的颜色相同但相反的颜色,尽管.coffee显示的颜色相反。
就像检测背景应该是哪种颜色的循环在第一次“通过”之后停止一样。
错误还是糟糕的代码?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;
}
}发布于 2016-04-04 12:29:43
您可以在单个仪表板上多次使用一个小部件,但听起来您已经让这部分工作了。
您需要淡出小部件,设置背景色,然后再次淡入。否则,您将看不到背景颜色更改,因为渲染已经发生。
onData: (data) ->
if @get('last')
if parseInt(@get('current')) > parseInt(@get('last')) then $(@node).fadeOut().css('background-color', "#006600").fadeIn() else $(@node).fadeOut().css('background-color', "#660000").fadeIn()
希望这能有所帮助。
https://stackoverflow.com/questions/36364349
复制相似问题