(Railsの)どのようにリンクを壊すことなく「はlink_to_remote」のテキストを置き換えますか?

StackOverflow https://stackoverflow.com/questions/1169582

質問

「はlink_to_remote」内のテキストを更新し、機能的なリンクを残す品質の方法はありますか?基本的に私は2つのリンクがあります:

  <%= link_to_remote "(#{building.charts.size} Charts)",{:url => {:action => "update_chart_matrix", :chartable_type => "building",:chartable_id => building.id, :title => building.name},
    :update => 'chart-matrix',
}
%>

...と...

<%= link_to_remote "Add Chart",{:url => {:action => "add_chart_for_chartable", :chartable_type => "building",:chartable_id => building.id},
    :update => 'other_link', #really not sure about this part as I only want to update the Chart Count in the other link
}
%>

単に、リンク内のHTMLを交換するのは簡単だろうが、私はその機能を「壊す」する必要はありません。任意のアイデア?

感謝します。

役に立ちましたか?

解決

リンクの内部HTMLを更新するonclick機能は中断されません。あなたは、innerHTMLプロパティですセット(レール経由)のプロトタイプでの更新を、使用している:

update: function(element, content) {
  element = $(element);
  if (content && content.toElement) content = content.toElement();
  if (Object.isElement(content)) return element.update().insert(content);
  content = Object.toHTML(content);
  // This sets innerHTML, it doesn't destroy the object
  element.innerHTML = content.stripScripts();
  content.evalScripts.bind(content).defer();
  return element;
},

限り戻ってくる内容がaタグ内に住むのに適しているとして、あなたは問題ないはずです。

グッドラック!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top