web2py components

☆樱花仙子☆ 提交于 2019-12-11 03:26:09

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/14332136/web2py-components

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!