gpt4 book ai didi

javascript - 数据表 javascript - RoR

转载 作者:行者123 更新时间:2023-12-01 01:29:52 25 4
gpt4 key购买 nike

当我更改页面时,我不会加载数据表,但如果在刷新页面时加载数据表:

当我第一次访问该页面时 enter image description here

当我去看望学生时 enter image description here

当他返回学生页面时 enter image description here

我的数据表js:

$(document).ready(function () {
$("#alumnos_table").dataTable({
destroy: true,
responsive: true,
"autoWidth": true,
"oLanguage": {
"sProcessing": "Procesando...",
"sLengthMenu": "Mostrar _MENU_ registros",
"sSearch": "",
"sZeroRecords": "No existen datos",
"sInfo": "Registro _START_ al _END_ de _TOTAL_ registros",
"sInfoEmpty": "Registro 0 al 0 de 0 registros",
"sLoadingRecords": "Cargando...",
"sInfoFiltered": "(Filtrado de _MAX_ registros)",
bDestroy: true,
paging: false,
searching: false,
"oPaginate": {
"sFirst": "Primero",
"sLast": "Último",
"sNext": "Siguiente",
"sPrevious": "Anterior"
},
"oAria": {
"sSortAscending": ": Activar para ordenar la columna de manera ascendente",
"sSortDescending": ": Activar para ordenar la columna de manera descendente"
}
},
"aoColumnDefs": [
{"bSortable": false, "aTargets": [7]}
],
bProcessing: true,
bServerSide: true,
"sAjaxSource": "/client/alumnos"
});
});

我的路线:

namespace :client do
get "index" => "index#index"
resources :alumnos
resources :asignaturas
resources :carreras
end

我的行动指数:

def index
respond_to do |format|
format.html
format.json {render json: AlumnosDataTable.new(view_context)}
end
end

关于如何解决这个问题有什么想法吗?

最佳答案

如果您在应用程序中使用 turbolinks,这可能就是其原因。

尝试替换:

$(document).ready(function () { 
....
....
})

与:

document.addEventListener("turbolinks:load", function () {
....
....
})

或者这个:

$(document).on('turbolinks:load', function() {
....
});

关于javascript - 数据表 javascript - RoR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53388161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com