【问题标题】:How to get dynatable json rails to work如何让可动态的 json rails 工作
【发布时间】:2014-01-25 22:29:17
【问题描述】:

我正在尝试使用 rails 使 ajax 加载 json 变得可动态化,但我收到一个错误,我需要帮助解释。我该如何设置?

控制台

TypeError: 'undefined' is not an object (evaluating 'settings.dataset.records.length')

日志

Started GET "/subjects/index.json?page=1&perPage=10&offset=0" for 127.0.0.1 at 2014-01-25 23:20:47 +0100
Processing by SubjectsController#index as JSON
  Parameters: {"page"=>"1", "perPage"=>"10", "offset"=>"0"}
  Subject Load (3.0ms)  SELECT "subjects".* FROM "subjects"
Completed 200 OK in 3035ms (Views: 0.1ms | ActiveRecord: 3.0ms)
[2014-01-25 23:20:50] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

SUBJECT.JS

jQuery(document).ready(function() {
      $('#subjects-table').dynatable({
        table:{
                defaultColumnIdStyle: 'underscore',
        },

      dataset: {
        ajax: true,
        ajaxUrl: '/subjects/index.json',
        ajaxOnLoad: true,
        contentType: "application/json; charset=utf-8",
        records: []

      }

    });
});    

Subjects_controller

class SubjectsController < ApplicationController

    def index
        @subjects = Subject.all
        respond_to do |format|
            format.html
            format.json {render :json => @subjects.to_json}
        end
    end

end

【问题讨论】:

    标签: jquery ruby-on-rails json dynatable


    【解决方案1】:

    看看应该如何处理 AJAX 响应:http://www.dynatable.com/dynatable-ajax.json

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多