Hey ich bin ein neuer Programmierer in RoR, HTML, CSS und JS gestartet lief in ein bisschen ein Problem, dass ich nicht sicher, wie zu beheben, suchte im Internet und könnte ' Ich finde eine Antwort, also hier ist es.Wie man jquery stack/zusammen arbeiten
Ich habe eine Datumsauswahl und 2 Dropdown-Menü, aber ich kann sie nicht zusammen arbeiten, jedes Mal, wenn ich etwas wähle es aktualisiert alles. Hier ist, wie der Code aussieht.
<script type="text/javascript">
$(function() {
function cb(start, end) {
$('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
}
cb(moment(), moment());
$('#reportrange').daterangepicker({
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')],
'This Year': [moment().startOf('year'), moment()]
}
}, cb);
$('#reportrange').on('apply.daterangepicker', function(ev, picker) {
//do something, like clearing an input
data = {
startDate: picker.startDate.format(),
endDate: picker.endDate.format()
}
window.location.href = "/invoices?startDate=" + data["startDate"] + "&endDate=" + data["endDate"]
});
});
</script>
<script type="text/javascript">
$(function(){
$(".dropdown-menu li a").click(function(){
choice = $(this).text()
if(choice == "Normal"){
$("tr.false").show()
$("tr.true").hide()
}else if(choice == "Special"){
$("tr.false").hide()
$("tr.true").show()
}else if(choice == "Pudu"){
$("tr[data-id='2']").hide()
$("tr[data-id='1']").show()
window.location.href = "/invoices?hotel_id=" + 1
}else if(choice == "Kota"){
$("tr[data-id='1']").hide()
$("tr[data-id='2']").show()
window.location.href = "/invoices?hotel_id=" + 2
}else if(choice == "All"){
$("tr").show()
}
$(this).closest(".dropdown").find(".btn").text(choice)
console.log($(this))
});
});
</script>
Jede Hilfe wird
heren den Ruby-Code geschätzt.
Controller
def index
@startDate = Date.parse(params[:startDate]) if params[:startDate]
@endDate = Date.parse(params[:endDate]) if params[:endDate]
@invoices = Invoice.all
if params[:startDate]
@invoices = @invoices.where("created_at >= ?", @startDate).where("created_at <= ?", @endDate.tomorrow)
else
@invoices = @invoices.where("created_at >= ?", Date.today)
end
if params[:hotel_id]
@invoices = @invoices.where(hotel_id: params[:hotel_id])
end
und heres in der Ansicht
<% @invoices.each do |inv| %>
<tr class="<%= inv.special %> data-item" data-id ="<%= inv.hotel_id %>">
<td><%= link_to inv.name, invoice_path(inv) %></td>
<td><%= inv.identification %></td>
<td><%= inv.room %></td>
<td><%= inv.rate * inv.days %></td>
<td class="col-md-1"><%= link_to "Edit", edit_invoice_path(inv)%></td>
<% if current_user.sk?%>
<td class="col-md-1"><%= link_to "Delete", inv, method: :delete, data: {confirm: 'Are you sure you want to delete this invoice?'} %></td>
<% end %>
</tr>
<% end %>
Bitte geben Sie den vollständigen Code (auch die HTML), besser, wenn Sie jsfiddle –