2011-03-17 170 views
0

我试图使用gridify网格控件来源:https://github.com/linoj/gridify的Rails如何呈现动态JavaScript

我做的一切都是为https://github.com/linoj/gridify说,但我发现我的视图页面上的JavaScript代码。有任何想法吗? 我在index.html.rb上写了<%= @grid%>。它看起来像轨道逃逸JavaScript代码,而我看到的视图页,而不是实际电网对这个代码:

<script type="text/javascript"> function gridify_fluid_recalc_width(){ if (grids = jQuery('.fluid.ui-jqgrid-btable:visible')) { grids.each(function(index) { gridId = jQuery(this).attr('id'); gridParentWidth = jQuery('#gbox_' + gridId).parent().width(); jQuery('#' + gridId).setGridWidth(gridParentWidth); }); } }; jQuery(window).bind('resize', gridify_fluid_recalc_width); function gridify_action_error_handler(r, data, action){ if (r.responseText != '') { return [false, r.responseText]; } else { return true; } } jQuery(document).ready(function(){ grid = jQuery("#contacts_grid").jqGrid({"beforeSelectRow": function(){ false; },"resizeStop": gridify_fluid_recalc_width,"autowidth":true,"rowNum":-1,"gridview":true,"restful":true,"url":"/contacts","hidegrid":false,"xmlReader":{"total":"contacts>total_pages","row":"contact","id":"id","root":"contacts","page":"contacts>page","records":"contacts>total_records","repeatitems":false},"forceFit":true,"datatype":"xml","postData":{"grid":"grid"},"colModel":[{"label":"Id","name":"id","sorttype":"integer","align":"right","index":"id","hidden":true},{"label":"Title","name":"title","sorttype":"text","index":"title"},{"label":"Address","name":"address","sorttype":"text","index":"address"},{"label":"Phone1","name":"phone1","sorttype":"text","index":"phone1"},{"label":"Phone2","name":"phone2","sorttype":"text","index":"phone2"},{"label":"Fax","name":"fax","sorttype":"text","index":"fax"},{"label":"Registration Number","name":"registration_number","sorttype":"text","index":"registration_number"},{"label":"Identity Number","name":"identity_number","sorttype":"text","index":"identity_number"},{"label":"National Code","name":"national_code","sorttype":"text","index":"national_code"},{"label":"Father Name","name":"father_name","sorttype":"text","index":"father_name"},{"label":"Birthday","name":"birthday","sorttype":null,"index":"birthday"},{"label":"Contact Type","name":"contact_type_id","sorttype":"integer","align":"right","index":"contact_type_id"},{"formatoptions":{"srcformat":"UniversalSortableDateTime","newformat":"FullDateTime"},"label":"Created At","name":"created_at","formatter":"date","sorttype":"date","index":"created_at"},{"formatoptions":{"srcformat":"UniversalSortableDateTime","newformat":"FullDateTime"},"label":"Updated At","name":"updated_at","formatter":"date","sorttype":"date","index":"updated_at"},{"label":"City","name":"city_id","sorttype":"integer","align":"right","index":"city_id"}],"hoverrows":false}) .addClass("fluid") .jqGrid('gridResize', {"minHeight":80,"handles":"s","minWidth":150}); grid[0].toggleToolbar(); });</script> 

回答

0

我得到了答案,我需要使用<%= raw @grid %> ,但我不知道为什么它不是网格化的文档。

+1

它可能没有在文档中,因为该项目自Rails 3问世以来尚未更新。 Rails 3中的默认渲染是自动调用“h”,并通过调用raw来覆盖它。这实际上与Rails 2相反。 – blu 2011-03-17 14:20:11