我想在同一视图中加载不同的web2py组件,但不能同时加载.我有5个.load文件,这些文件具有针对不同情况的表单字段,这些文件由onchange选择脚本动态调用.使用web2py可以做到这一点吗?
I would like to load different web2py components in the same view, but not at the same time. I have 5 .load files which have form fields for a different scenario, these are called dynamically by an onchange select script. Is it possible with web2py to do this?
推荐答案是的,但是在那种情况下,请不要在web2py视图中使用LOAD()帮助程序,因为这会生成Javascript,该Javascript会在页面上立即加载组件加载.相反,创建一个具有ID的div来容纳组件,并让您的onchange事件处理程序以div的id为目标调用web2py_component()函数:
Yes, but in that case, don't use the LOAD() helper in the web2py view, as that will generate Javascript that loads the component immediately upon page load. Instead, create a div with an id to hold the component, and have your onchange event handler call the web2py_component() function with the id of the div as the target:
<div id='mycomponent'></div> <script> $(function() { $('some_selector').change(function() { web2py_component('{{=URL('default', 'mycomponent')}}', target='mycomponent'); }); }); </script>更多推荐
web2py组件
发布评论