jquery - Making a live counter start when an element in array changes? -


i have data feed api returns array of arrays "name", "call status", , "time" fields:

[["alex", "wrap", "1395673193"], ["bill", "call", "1395673370"], ["chelsea", "wait", "1395673363"], ["david", "wait", "1395673374"], ["kirsty", "call", "1395673340"], ["natalie", "wait", "1395673360"], ["rose", "wait", "1395673374"], ["shirley", "wait", "1395673378"], ["stuart", "call", "1395673101"], ["wendy", "call", "1395673352"]] 

the time uxix time stamp don't think need now.

i display them in view jquery partial refreshing every second:

<% @ta.each |elem| %>   <td><%  elem.each_slice(3) |a,b,c| %></td>  <td><%=  %></td>  <td><%=  b %></td>  <td><%=  c %></td> <% end %> <% end %> 

what display live counter, stopwatch, resets everytime b changes can't figure out how trigger clock starting.

i have tried adding somthing following view refreshed jquery every second:

 <td><%  elem.each_slice(3) |a,b,c| %></td>  <td><%=  %></td>  <td><%=  b %></td>  <td><%= (b == @timecheck ? "0" : "1" ) %></td>  <% @timecheck = b %> <% end %> 

with logic being "1" should appear , return "0" on next iteration, meaning use trigger. not work because holds value previous agent rather same agent on previous loop, if me.

i suspect doing way in view, , logic should in controller, can move once working. it's mashup of things trying.

i think might going wrong, i'm new @ this.

after few days, figured out! incase helps else, here how did it. stores status in opposite arrays on each loop, can compare 1 loop other see if there change.

count = 0 @changeodd = hash.new @changeeven = hash.new @time = hash.new loop   count = count + 1   = agentfeed.get("http://myapi/ajax.php?token=""#{@token}""&method=agents&action=read")   b = a["list"]   @feedarray = []      b.each |feed|       name = feed["name"]      status = feed["status"]    if count.odd?      @changeodd[name] = status      if @changeeven[name] == status         @time[name] = @time[name] + 1      else     @time[name] = 1      end    else      @changeeven[name] = status      if @changeodd[name] == status     @time[name] = @time[name] + 1      else     @time[name] = 1      end    end   @feed = [] @feed << name << status << @time[name] @feedarray << @feed  end 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -