德鲁帕尔。使用 AJAX 更新视图内容
我在 Drupal 中创建了一个视图,用于检索节点列表。该视图的显示是一个页面,并且效果非常好。它甚至允许我通过参数过滤其内容。
查看当前的视图配置(点击放大):
我想使用 AJAX 来使用过滤器 (通过参数)功能,无需重新加载页面。我已启用“使用 AJAX”选项,但我不确定如何继续。 关于如何做到这一点有什么想法吗?
顺便说一句,我正在构建自己的主题(以防改变任何内容)。
更新: 基本上,当我浏览section/parameter1、section/parameter2...时,此视图有效,但我想对 AJAX 执行相同的操作,而无需重新加载页面。我希望现在更清楚了
I've created a view in Drupal that retrieves a list of nodes. The display of this view is a page and it works perfectly well. It does even allow me to filter its content by argument.
See the current's view configuration (click to enlarge):
I want to use AJAX to use the filter (by parameter) functionality without reloading the page. I've enabled the "Use AJAX" option but I am not sure on how to continue.
Any ideas on how to do that?
By the way, I'm building my own theme (in case that changes anything).
Update:
Basically, this view works when I browse through section/parameter1, section/parameter2... but I want to do the same with AJAX, without reloading the page. I hope is clearer now
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
尽管这个问题可能已经解决了,但最好的“Drupalistic 方式”在这个截屏视频中进行了解释:
http://seanbuscay.com/ajax-reader-demo
这并不难,并且可以用于视图或渲染完整节点。
根据截屏视频的作者(我可以向您保证这是正确的),以下是要记住的步骤:
菜单回调。
已加载到页面中。
Even though this probably has been solved by this time, the best "Drupalistic way" to do it is explained in this screencast:
http://seanbuscay.com/ajax-reader-demo
It is not that hard, and works either with views or rendering full nodes.
According to the author of the screencast (and I can ensure you it is all right), this are the steps to remember:
menu callback.
loaded in the page.
这是我最终使用 ajax 加载视图块并从我在页面上创建的链接列表的 href 值传递上下文过滤器的 javascript。希望这对某人有帮助!
Here is the javascript I ended up using to load the views block with ajax and pass in the contextual filter from the href value of a list of links I created on page. Hope this helps someone!
我不清楚“使用过滤器(按参数)”是什么意思。当给定页面上的选择标准发生更改时,AJAX 视图会更新结果。您似乎没有可能更改的选择标准,因此无需使用 AJAX 进行更新。可能更改的选择标准包括页面(您已关闭分页)和公开的过滤器(您的过滤器未公开)。它不包括参数(您拥有),因为这些参数不会在单个页面上更改,而是在页面之间更改。
It's not clear to me what you mean by "to use the filter (by parameter)." AJAX views update the results when selection criteria changes on a given page. You appear to have no selection criteria that might change, so there's nothing to update with AJAX. Selection criteria that might change includes page (you have paging off) and exposed filters (your filter is not exposed). It does not include arguments (which you have), since those don't change on a single page but rather between pages.
好吧,我找到了一个快速但肮脏的解决方案。您可以构建一个呈现视图的 php 文件,然后使用 ajax.load 在 div 中打印它。
ajax 调用:
ajax 文件 (ajax_all_projects.php):
我认为这可以解决问题。我希望它对其他人有帮助。 :)
Ok, I found a quick'n'dirty solution. You can build a php file that renders the view and then use ajax.load to print it in a div.
The ajax call:
The ajax file (ajax_all_projects.php):
I think that does the trick. I hope it helps someone else. :)
您还可以使用以下内容
从 hook_menu 创建一个页面,并在菜单函数中,调用
do 例如,如果您有一个参数
,而不是
您也可以使用
you can also use the following
create a page from hook_menu and in the menu function, call
do for example if you have a parameter
instead of
you could also use