加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 无法读取未定义的属性’asSorting’ – DataTa

发布时间:2020-12-17 02:04:16 所属栏目:百科 来源:网络整理
导读:for(j = 0,jLen = oColumn.asSorting.length; j jLen; j)在DataTables的第6706行...... 我在主题上复制了 railscast,几乎是逐字逐句.所以oColumn是未定义的.互联网告诉我,我需要 thead和 th值… 视图: table id="companyBoxList" class="display" data-sour
for(j = 0,jLen = oColumn.asSorting.length; j< jLen; j)在DataTables的第6706行...... 我在主题上复制了 railscast,几乎是逐字逐句.所以oColumn是未定义的.互联网告诉我,我需要< thead>和< th>值…

视图:

<table id="companyBoxList" class="display" data-source="<%= comp_boxes_path(format: "json") %>"
  <thead>
    <tr>
      <th>uid</th>
      <th>length</th>
      <th>width</th>
      <th>height</th>
      <th>weight</th>
      <th>trips</th>
    </tr>
  </thead>
  <tbody>
  </tbody>
</table>

这是新课程的副本.再次,几乎复制了railscast

boxes_database.rb

class BoxesDatatable
  delegate :params,:h,:link_to,:number_to_currency,to: :@view

  def initialize(view)
    @view = view
  end

  def as_json(options = {})
    {
      sEcho: params[:sEcho].to_i,iTotalRecords: Box.count,iTotalDisplayRecords: boxes.count,aaData: data
    }
  end

private

  def data
    boxes.map do |box|
      [
        box.uid,box.length,box.width,box.height,box.weight,box.trips
      ]
    end
  end

  def boxes
    @boxes ||= fetch_boxes
  end

  def fetch_boxes
    boxes = Box.order("#{sort_column} #{sort_direction}")
    boxes = boxes.page(page).per(per_page)
    if params[:sSearch].present?
      boxes = boxes.where("uid like :search or trips like :search",search: "%#{params[:sSearch]}%")
    end
    boxes
  end

  def page
    params[:iDisplayStart].to_i/per_page + 1
  end

  def per_page
    params[:iDisplayLength].to_i > 0 ? params[:iDisplayLength].to_i : 10
  end

  def sort_column
    columns = %w[uid length width height weight trips]
    columns[params[:iSortCol_0].to_i]
  end

  def sort_direction
    params[:sSortDir_0] == "desc" ? "desc" : "asc"
  end
end

javascript(咖啡):

jQuery ->
  $('#companyBoxList').dataTable
    sPaginationType: "full_numbers"
    bJQueryUI: true
    bProcessing: true
    bServerSide: true
    sAjaxSource: $('#companyBoxList').data('source')

我能够通过添加“aoColumns”来处理这个问题:[null,null,null].这会使标题归零,这会破坏目的.这指出了正在读取的头文件的问题,而不是json,因为数据返回正常.

想法?

解决方法

语法错误…缺少结束>在我最初的表呼叫.检查我的代码的第一行.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读