簡體   English   中英

在Rails應用中將html從json剝離到jqgrid

[英]strip html from json to jqgrid in rails app

在我的Rails應用程序中,我將在http://github.com/linoj/gridify的幫助下設置自己的管理員。 這確實非常有效,但有一個例外:HTML在表格視圖中呈現,這使單元格瘋狂起來。 我用

white-space:nowrap;

在我的CSS中,這有助於避免其他格式問題。

我仍然需要在到達表之前擺脫html或在渲染表時忽略它(我認為這很難做到)

我所擁有的是一個控制器和一個索引視圖,可以為我生成網格:

在控制器中:

def index
 statics = Static.find(:all) do
  if params[:_search] == "true"
   name    =~ "%#{params[:name]}%" if params[:name].present?
   content  =~ "%#{params[:content]}%" if params[:content].present?                      
  end
  paginate :page => params[:page], :per_page => params[:rows]      
  order_by "#{params[:sidx]} #{params[:sord]}"
end

respond_to do |format|
  format.html
  format.json { render :json => statics.to_jqgrid_json([:id,:name,:content], params[:page], params[:rows], statics.total_entries) }
end
end

在index.html.erb中:

<%= jqgrid("Static Pages", "statics", "/admin/statics",
[
{ :field => "id", :label => "ID", :width => 35, :resizable => false },
{ :field => "name", :label => "Name", :width => 100, :editable => true },
{ :field => "content", :label => "Content", :width => 800, :editable => true, :edittype => "textarea", :editoptions => { :rows => 20, :cols => 60 } }
], { :add => true, :edit => true, :inline_edit => false, :delete => true, :edit_url => "/admin/statics/post_data" }
) %>

有誰知道我如何實現此操作,使html被轉義/剝離……什么最有效?

我猜想這個問題不會解決,並且我承認我沒有找到一種解決問題的優雅方法。 為了完整起見,這是我在CSS中所做的,以使事情顯示我想要的方式:

td {height:22px;white-space:nowrap;overflow:hidden;}
p {display:inline;}
br {display:none;}
h3 {display:inline;}
...

我對br標簽特別滿意,因為導入數據的維護者過度使用了它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM