I have a partial that initial displays a table of active workflows. There is a link_to in the partial that rerenders it with all workflows, to allow people to see them all if they wish.
我有一个部分,初始显示活动工作流程表。部分中有一个link_to,它将所有工作流程重新渲染,以便人们可以根据需要查看所有工作流程。
All works fine, except I'm using tablesorter and jQuery and when I rerender the partial, I lose the table sorting and some of the jQuery styles. I think it's because some classes on some HTML elements go missing.
一切正常,除了我使用tablesorter和jQuery,当我重新渲染部分时,我丢失了表排序和一些jQuery样式。我认为这是因为某些HTML元素上的某些类缺失了。
I guess it's because things get initialized on document ready in application.js and those calls are not made on the AJAX rerender.
我想这是因为在application.js中的文件准备就绪已初始化,而且这些调用不是在AJAX重新渲染上进行的。
What I'm not sure of is how to fix it . . . ?
我不确定的是如何解决它。 。 。 ?
1 个解决方案
#1
0
You need to call the initialisation code again at the end of your Ajax request. Like you said, the jQuery behaviour is applied in the ready event, so it won't apply to DOM elements created after that.
您需要在Ajax请求结束时再次调用初始化代码。就像你说的那样,jQuery行为应用于ready事件,因此它不适用于之后创建的DOM元素。
As an aside, jQuery has .live
function to mitigate this issue for event handlers. It applies the handler to any element that matches the selector regardless of when it was created.
顺便说一下,jQuery有.live函数来缓解事件处理程序的这个问题。它将处理程序应用于与选择器匹配的任何元素,无论它何时创建。
#1
0
You need to call the initialisation code again at the end of your Ajax request. Like you said, the jQuery behaviour is applied in the ready event, so it won't apply to DOM elements created after that.
您需要在Ajax请求结束时再次调用初始化代码。就像你说的那样,jQuery行为应用于ready事件,因此它不适用于之后创建的DOM元素。
As an aside, jQuery has .live
function to mitigate this issue for event handlers. It applies the handler to any element that matches the selector regardless of when it was created.
顺便说一下,jQuery有.live函数来缓解事件处理程序的这个问题。它将处理程序应用于与选择器匹配的任何元素,无论它何时创建。