如果我有一个返回json的控制器,如何使用jquery将json数据结果加载到页面中,我的网页也使用了远程true,所以请求将是ajax,结果json返回到页面,现在我需要将json数组加载到handsontable中。我需要将json调用返回的数据绑定到handsontable对象中。
class GradesController < ApplicationController
def index
logger.debug params
respond_to do |format|
format.html
format.json { render json: GradesDatatable.new(view_context) }
#format.js { @result = GradesDatatable.new(view_context).as_json }
end
end
end
页面
<div class="row">
<%= simple_form_for :filters, url: grades_index_path('json'), method: :get, :remote => true do |f| %>
<div class="small-4 columns">
<%= f.input :curso, collection: Curso.all, :label_method => "nombre", :value_method => "nombre" %>
<%= f.input :seccion, collection: Seccion.all, :label_method => "nombre", :value_method => "nombre" %>
<%= f.collection_radio_buttons :tanda, [['M', 'Matutina'] ,['D', 'Despertina'],['N', 'Nocturna']], :first, :last, :checked => 'M' %>
</div>
<div class="small-3 columns">
<div class="form-actions">
<%= f.button :submit, "Filtrar", :class => "button large" %>
</div>
</div>
<% end %>
</div>
<div class="row">
<div id="grades"></div>
</div>
JS
$(function(){
data = []
window.data = data.aaData
var container = document.getElementById('grades');
window.hot = new Handsontable(container,
{
data: window.data,
...