我的数据表似乎功能齐全 - 我所有列的过滤和排序都有效,但我仍然在我的控制台中收到此错误:Uncaught TypeError: Cannot set property 'data' of null(…)
以下是最重要的部分:
notifications_datatable.rb
class NotificationsDatatable
delegate :params, :h, :link_to, :content_tag, to: :@view
def initialize(view)
@view = view
end
def as_json(options = {})
{
draw: params[:draw].to_i,
recordsTotal: total_records,
recordsFiltered: notifications.total_entries,
data: data
}
end
index.html.slim
table#notifications.dataTable.table.table-hover.table-nomargin.dataTable-tools.table-bordered.dataTable-custom.display data-source="<%= notifications_url(format: 'json') %>"
thead
tr
th style="width: 94px;"
= t('.client_id')
th = t('.request_type')
th = t('.applicant_name')
th = t('.organisation')
th = t('.sent_at')
th data-orderable="false"
= t('.actions')
tbody
javascript:
$('#notifications').dataTable({
responsive: true,
PagingType: "full_numbers",
processing: true,
serverSide: true,
ajax: $('#notifications').data('data')
});
如果我在控制台中展开TypeError,我会看到这个javascript,而ajaxData
部分下面有一条红色的卷曲线。
else
{
// Object to extend the base settings
oSettings.jqXHR = $.ajax( $.extend( baseAjax, ajax ) );
// Restore for next time around
ajax.data = ajaxData;
有没有人见过这个?
答案 0 :(得分:0)
尝试更改此行:
ajax: $('#notifications').data('data')
为:
ajax: $('#notifications').data('source')