【问题标题】:(Rails) How do you replace the text of a "link_to_remote" without breaking the link?(Rails)如何在不破坏链接的情况下替换“link_to_remote”的文本?
【发布时间】:2009-07-23 04:18:51
【问题描述】:

是否有一种优质的方法来更新“link_to_remote”中的文本并保持链接正常工作?基本上我有两个链接:

  <%= 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 就很容易了,但我不想“破坏”它的功能。有什么想法吗?

谢谢。

【问题讨论】:

    标签: javascript ruby-on-rails updating link-to-remote


    【解决方案1】:

    更新链接的内部 HTML 不会破坏 onclick 功能。您正在原型中使用更新(通过 Rails),它设置为 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 标签内,就可以了。

    祝你好运!

    【讨论】:

      猜你喜欢
      • 2020-01-11
      • 1970-01-01
      • 2014-08-21
      • 1970-01-01
      • 1970-01-01
      • 2017-09-14
      • 1970-01-01
      • 1970-01-01
      • 2010-12-21
      相关资源
      最近更新 更多