web2py:如何检测 LOAD 组件何时通过 ajax 加载? [英] web2py: how to detect when an LOAD component has loaded via ajax?

查看:19
本文介绍了web2py:如何检测 LOAD 组件何时通过 ajax 加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 {{=LOAD(...)}} 将一个组件注入到我的 web2py 页面中,如 http://web2py.com/books/default/chapter/29/12/components-and-plugins#LOAD,但我需要在组件加载后触发一些 javascript.通常,如果通过 ajax 加载某些内容,则会出现成功回调.如何在 web2py 中通过 {{=LOAD(...)}} 设置其中之一?

I'm injecting a component into my web2py page using {{=LOAD(...)}} as described at http://web2py.com/books/default/chapter/29/12/components-and-plugins#LOAD, but I need to fire off some javascript once the component is loaded. Normally if something is loaded via ajax, there is a success callback. How can I set one of this via {{=LOAD(...)}} in web2py?

推荐答案

最简单的方法是在组件的控制器中设置 response.js :

The simplest approach would be to set response.js in the controller of the component:

def mycomponent():
    response.js = 'alert("mycomponent just loaded");'
    return dict()

或者,您可以直接在组件本身中包含一个

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