2016-11-03 59 views
0

我的數據表中出現的空無法設置屬性「數據被充分發揮作用 - 過濾和我所有的列上工作的排序,但我仍然得到這個錯誤在我的控制檯: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

嘗試改變這一行:

ajax: $('#notifications').data('data') 

到:

ajax: $('#notifications').data('source')