Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在jqGrid中访问ajax调用数据_Ruby On Rails_Ajax_Jquery_Jqgrid - Fatal编程技术网

Ruby on rails 如何在jqGrid中访问ajax调用数据

Ruby on rails 如何在jqGrid中访问ajax调用数据,ruby-on-rails,ajax,jquery,jqgrid,Ruby On Rails,Ajax,Jquery,Jqgrid,我有一个ajax调用,用于从服务器获取rails应用程序中jqGrid的数据 $(document).ready(function() { colNamesData = ['Project', 'Activity', 'Description', 'Hours', 'Date',''] colModelData = [ {name:'projects.name',index:'projects.name', width:130,

我有一个ajax调用,用于从服务器获取rails应用程序中jqGrid的数据

$(document).ready(function() {
     colNamesData = ['Project', 'Activity', 'Description', 'Hours', 'Date','']
     colModelData = [ 
                      {name:'projects.name',index:'projects.name', width:130, sorttype:"text"}, 
                      {name:'creation_date',index:'creation_date', width:130, sorttype:"date"},
                      {name:'buttons', index:'buttons', width:270, align:'center', search:false}
                   ]

$("#time_sheet_table").jqGrid({
      datatype: 'json',
      colNames: colNamesData,
      colModel: colModelData,
      url: 'timesheets/timesheet_index_jqgrid?table_name = timesheet_index_jqgrid&',
      mtype: "Get",
      jsonReader: {
        root: "rows",
        page: "page",
        total: "total",
        records: "records",
        id: "id",
        repeatitems: true,
        cell: 'cell',
        button: "buttons",
      },  
这是我的控制器代码:

   if timesheet.deletable?(@user) 
      @buttons = 1
      buttons += "<div style='margin-right:55px'>"
      buttons += "<a class='button delete-button'  href='#' onclick=\"jQuery('#time_sheet_table').jqGrid('delGridRow', #{timesheet.id}, {});\"><span class='link'>Delete</span></a>" +  "</div>"

    end
    @cell << {
               :id => timesheet.id,
               :cell => [timesheet.project_name,timesheet.creation_date.strftime("%Y-%m-%d"),buttons]
            }
  end
list_of_resources = {
                      "total" => total_page(timesheets.count,grid_id),
                      "page" => session[:page][:time_sheet_table],
                      "records" => timesheets.count,
                      "rows" => @cell
                    }
我想从控制器中访问@按钮的值,但无法猜到如何在我的视图中传递和访问,以便我可以设置诸如ex

<% if @buttons == 1 %>
      colNamesData.splice(1,1);
      colModelData.splice(1,1);
  <% end %>

thanx

我不是RubyonRail的开发者,但是如果您使用jqGrid和任何服务器技术,最好的方法是只发送数据,而不在服务器响应中发送HTML标记。jqGrid有一个函数,允许您构造任何HTML fragmant,它将被放置在列中。您可以从服务器发送布尔值timesheet.deletable作为true和false或1和0,而不是当前的HTML片段。在自定义格式化程序中,您可以访问从服务器发送的每行对象参数的整行数据。根据从服务器返回的数据格式,应使用rowObject.creation\u date或数组索引rowObject[2]等命名属性

还有一句话。我不建议您在colModel的name属性中使用任何特殊字符。您应该使用名称:'name'或名称:'projects\u name',而不是名称:'projects.name'。如果点字符将放置在JSON数据行的属性名称中,那么在您的情况下,您不应该使用jsonmap:'projects.name'请参阅


最后一句话:colModel中的sorttype将仅用于本地数据,在数据类型为“json”的情况下将被忽略。

@oleg…thanx用于响应。。实际上我已将代码减少到maxm限制,因此似乎不清楚。Projects.name用于项目表。排序和搜索在服务器端处理。@GhostRider:for排序将用于索引,而不是名称属性。要访问所请求的数据,应与自定义格式化程序的rowObject参数以及loadComplete事件处理程序的data参数一起使用。