Rails操作后,JavaScript函数不起作用

时间:2016-07-15 02:27:49

标签: javascript jquery ruby-on-rails

我在控制器中定义了一个恢复操作,如下所示

def restore
  kid = Kid.find(params[:id])
  kid.update_attribute(:discharge_date, nil)
  redirect_to root_url
end

执行此操作的按钮是一个模态,它有效地将页面“刷新”回我的主页面,然而一些javascript函数不起作用,如点击功能和动态内容。我尝试在文件准备条款中移动它们,但这没有用。它们仅在我再次手动重新加载页面时才起作用。有什么建议吗?下面是我的JS文件。感谢。

 $(document).ready(function(){
    $(".landing-page").hide(0).delay(1100).fadeIn(1100)

    // JS for View Modal
    $(".table-striped").find('tr[data-id]').on('dblclick', function () {
        var kid_id = $(this).data('id');
        $.getJSON("/kids/" + kid_id, function(data) {
    // Render the modal body here
    // first_name = data.first_name, last_name = data.last_name etc
    $('#showTitle').html(data.first_name + ' ' + data.last_name)
    //Tab 1
    $('#first_name_show').html(data.first_name);
    $('#last_name_show').html(data.last_name);
    $('#dob_show').html(data.dob);
    $('#gender_show').html(data.gender);
    // Display Modal
    $('#showModal').modal('show');
    $("#dischargeBtn").attr("href", "/kids/" + kid_id + "/discharge");

    });        
  })


// JS for restore button and modal to function correctly

$(document).on("click", "#restoreBtn", function () {
     var kid_id = $(this).data('id');
     $("#confirm_restoreBtn").attr("href", "/kids/" + kid_id + "/restore");
     $.getJSON("/kids/" + kid_id, function(data) {
     $('.modal-body').html('<p>' + 'Are you sure you want to restore ' + data.first_name + ' ' + data.last_name + '?' + '</p>')
 });

});

// JS for clearing modal forms

$('.modal').on('hidden.bs.modal', function(){
    $(this).find('form')[0].reset();
});

// JS for switching between main dashboard and archived students

$('#archivedBtn').on('click',function(){
    if($('#dashboard').css('display')!='none'){
        $('#archived').show().siblings('div').hide();
        $('.add-student-btn').hide();
    }
});



$('#dashboardBtn').on('click',function(){
    if($('#archived').css('display')!='none'){
        $('#dashboard').show().siblings('div').hide();
        $('.add-student-btn').show();
    }
  });
});

0 个答案:

没有答案