(القضبان) كيف يمكنك استبدال نص "Link_to_Remote" دون كسر الرابط؟
-
19-09-2019 - |
سؤال
هل هناك طريقة جودة لتحديث النص داخل "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 داخل الرابط، لكنني لا أريد "كسر" وظائفه. أيه أفكار؟
شكرًا.
المحلول
تحديث 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
العلامة، يجب أن تكون على ما يرام.
حظا طيبا وفقك الله!
لا تنتمي إلى StackOverflow