web2py组件 [英] web2py components

查看:106
本文介绍了web2py组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在同一视图中加载不同的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组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆