0
我有一個Rails應用程序顯示錶中員工的輪班。用戶可以使用Best In Place寶石直接編輯0和shiftend
。使用jQuery刷新成功的DIV
我得到了數據庫工作的更新,但需要重新加載DIV
,因此顯示班次持續時間的欄或者根據開始和結束時間的變化展開或收縮。
我想我需要一些JavaScript來做到這一點,它可能很簡單,但我不能弄清楚:)
VIEW
<div class="shift-data">
<% @myShifts.where(:shiftdate => date).order(:shiftstart).each do |shift| %>
<div id="shift_<%= shift.id %>" class="shift-item span" style="width: <%= (shift.shiftend - shift.shiftstart)/60/60/24 * 100 %>%; left: <%= shift.shiftstart.seconds_since_midnight/60/60/24 * 100 %>%; top: 0px;">
<div class="hider" style="background-color: #<%= shift.type.color %>;">
<p>
<i class="icon gear"></i>
<%= best_in_place shift, :shiftstart, :type => :input, :display_with => :format_time_bip %> - <%= shift.shiftend.strftime("%H.%M") %> <span class="tag"><%= shift.type.name.upcase %></span>
</p>
</div>
</div>
<% end %>
</div>
的application.js
$(document).ready(function() {
/* Activating Best In Place */
jQuery(".best_in_place").best_in_place();
});
$(function() {
jQuery(".best_in_place").bind("ajax:success", function() {
/* It's here I need some help .... */
});
});
編輯:
提交的HTML:
<div class="shift-data">
<div id="shift_3" class="shift-item span" style="width: 58.333333333333336%; left: 8.333333333333332%; top: 0px;">
<div class="hider" style="background-color: #df5c64;">
<p>
<i class="icon gear"></i>
<span id="best_in_place_shift_3_shiftstart" class="best_in_place" data-original-content="2000-01-01 02:00:00 +0100" data-type="input" data-attribute="shiftstart" data-object="shift" data-url="/shifts/3">02.00</span>
- 16.00
<span class="tag">FERIE</span>
</p>
</div>
</div>
</div>
回調只是給了我新的值在數據庫中shiftstart。我需要刷新父DIV不知何故,所以包含酒吧的DIV得到刷新並顯示新的轉移持續時間。合理? :) – Twiddr
我需要刷新id =「shift _ <%= shift.id%>」,但不知道如何定位該特定DIV。 – Twiddr
如果您將問題中包含呈現的html,它會使事情變得更容易。我認爲你想更新div.shift-item的css。 –