Pergunta

Existe uma maneira qualidade para atualizar o texto dentro de um "link_to_remote" e deixar o link funcional? Basicamente, eu tenho dois links:

  <%= 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',
}
%>

... e ...

<%= 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
}
%>

Seria fácil o suficiente para simplesmente substituir o HTML dentro do link, mas eu não quero "quebrar" a sua funcionalidade. Alguma idéia?

Graças.

Foi útil?

Solução

Atualizando o HTML interno de um link não vai quebrar a funcionalidade onclick. Você está usando atualização no protótipo (via Rails), qual o conjunto é o 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;
},

Enquanto o conteúdo voltar é adequado para viver dentro de uma tag a, você deve ser fino.

Boa sorte!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top