2014-02-24 2 views
1

나는 dashing-rails을 사용 중이며 API에서 돌아 오는 부울 값에 따라 위젯의 배경색을 초록/빨강으로 변경하려고합니다.대시 - 레일 : 부울 데이터 값을 반영하도록 위젯의 배경색을 변경하는 방법?

Dashing.scheduler.every '1m', first_in: 8 do 
    Dashing.send_event('all_good', status: MixpanelHelper.all_good?) 
end 

그 커피 스크립트가 포함 된 위젯 :

onData: (data) -> 
    if data.status 
    $(@node).css('background-color', '#42b2aa') 
    else 
    $(@node).css('background-color', '#e85c28') 

및 그 ERB 포함하는 대시 보드 : 내가 가진 작업이

<div data-id="all_good" data-view="Mywidget" data-title="All good" data-goal="95%" data-suffix="%"></div> 

을하지만 색상 변경이 트리거되지 않습니다. 내 데이터를 올바르게 전달하지 않습니까?

답변

0

며칠 전 Dashing을 사용하기 시작했는데 같은 문제가있었습니다. 내가 해결 한 방법은 ready :와 onData : 두 가지 장소에 넣는 것입니다.

ready: -> 
    # This is fired when the widget is done being rendered 
    @setColor(@get('status')) 

    onData: (data) -> 
    # Handle incoming data 
    # You can access the html node of this widget with `@node` 
    # Example: $(@node).fadeOut().fadeIn() will make the node flash each time data comes in. 
    @setColor(@get('status')) 
    $(@node).fadeOut().fadeIn() 

    setColor: (status) -> 
    if status 
     switch status 
      when 'RUN' then $(@node).css("background-color", "#29a334") #green 
      when 'FAIL' then $(@node).css("background-color", "#b80028") #red 
      when 'PEND' then $(@node).css("background-color", "#ec663c") #orange 
      when 'HOLD' then $(@node).css("background-color", "#4096ee") #blue 

내가 사용할 수있는 다른 이벤트, 나는 아직까지 모릅니다 하나, 내가 찾을 경우이 대답을 업데이트 할 것이있을 수, 그것은 최선의 해결책이 아니라 생각하지만, 그 동안 당신은 수도 이것을 사용하고 싶다.

관련 문제