在动态生成的内容中维护 Javascript 功能
我正在寻找一种质量机制来为动态生成的表添加排序。我的视觉设置非常简单。左侧有一个菜单,其中包含一系列可供选择的项目(图表、图形、图像、表格等)。单击某个项目后,它将显示在页面右侧的“动态内容”div 中。一切都很好。
我遇到的问题是能够实现加载内容的某些动态功能。在这种特殊情况下,我有根据所选表格生成的动态内容,它出现在“动态内容”div 中,但 JavaScript 排序不起作用。我尝试将其包含在“应用程序布局”页面以及生成数据的部分中,但没有任何效果。但是,如果我将其放在“静态”页面中,则一切正常。关于如何让它发挥作用有什么想法吗?
仅供参考,我在 OS X 上使用 Rails 2.3.4,使用“sorttable.js”,以及 Safari 4.0.3 和 Safari 4.0.3。火狐3.5.5进行测试。
I'm looking for a quality mechanism to add sorting to dynamically generated tables. My visual setup is very simple. On the left side I have a menu with series of items to select from (charts, graphs, images, tables, etc.). Once an item is clicked, it will show up in the "dynamic-content" div on the right side of the page. That all works fine.
What I'm having issue with is being able to implement certain dynamic features of the loaded content. In this particular case, I have dynamic content that gets generated based on the table that is selected and it appears in the "dynamic-content" div, but the JavaScript sorting doesn't work. I've tried including it in the "Application Layout" page as well as in the partial that generates the data, but nothing works. However, if I put it in a "static" page all works fine. Any ideas on how to get this working?
FYI I'm using Rails 2.3.4 on OS X, using "sorttable.js", and Safari 4.0.3 & Firefox 3.5.5 to test.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑您需要在动态加载的表上调用
sorttable.makeSortable(); 。由于您没有提供任何有关如何切换表格的背景信息,因此很难提供解决方案。
Sorttable.js 依赖于 unobtrusive javascript,可排序的表格必须存在于 dom 中页面加载完毕。然后,Sortable.js 对每个具有“sortable”类的表调用 makeSortable。当您插入新表时,您需要执行相同的操作。
I would suspect that you need to call
sorttable.makeSortable(<table element>);
on your dynamically loaded tables. Since you didn't provide any background on how you're switching out your tables, it's hard to provide a solution.Sorttable.js relies on unobtrusive javascript, the tables to be sortable must be present in the dom when the page is finished loading. Sorttable.js then calls makeSortable on each table that has the "sortable" class. When you insert your new table, you need to do the same.
如果没有更多信息,就很难找到解决方案。但是您是否尝试过使用 Firebug 查看生成的页面以了解发生了什么?你的 IDE 有 Javascript 调试器吗?
Well without more info it'll be hard to come up with a solution. But have you tried looking at the generated page with Firebug to see what's going on? Does your IDE have a Javascript debugger?