web2py:使用 LOAD 中的函数(ajax)
是否可以将 =LOAD(...) 与函数而不是控制器/函数字符串一起使用,
例如:
Controller:
def test():
print "test"
def index():
return dict(test=test)
View:
{{=LOAD(test, ajax=True)}}
而不是:
View:
{{=LOAD('controller', 'test', ajax=True)}}
主要原因是,我想使用无法通过这种方式访问的 lambda/生成函数。
Is it possible to use =LOAD(...) with a function rather then controller/function string
e.g:
Controller:
def test():
print "test"
def index():
return dict(test=test)
View:
{{=LOAD(test, ajax=True)}}
rather then:
View:
{{=LOAD('controller', 'test', ajax=True)}}
The main reason being, I want to use lambda/generated functions which cannot be accessed this way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不。但这并不是因为不支持该语法,而是因为这在逻辑上是不可能的:LOAD() 是在与执行 lambda 的请求不同的 http 请求中执行的,因此后者将是未定义的。此外,要执行ajax回调,被调用的函数必须有一个名称,不能是lambda。我们可以创造性地使用缓存,以便 LOAD 将 lambda 存储在缓存中:
但这仅适用于 cache.ram,并且需要定期清理缓存。
No. But not because the syntax is not supported, because it is logically impossible: the LOAD() is executed in a different http request than the one in which the lambda would be executed and therefore the latter would be undefined. Moreover to perform the ajax callback, the called function must have a name, cannot be a lambda. We could come up with a creative use of cache so that LOAD stores the lambda in cache:
But this would only work with cache.ram and would require periodic cache cleanup.