我一直在使用web2py开发应用程序。我有一个带回调链接的页面,它将信息发送到另一个函数,这会通过页面右侧边栏中的ajax加载结果。单击链接时,链接本身会消失,但结果会正确加载。我必须刷新页面才能返回链接。我一直在看这个年龄但是无法弄清楚,我对web2py相对较新,所以可能错过了一些明显的东西。 这是一些代码:
视图(带链接):
{{if hosts == "Please select a category":}}
{{response.write("Please select a category")}}
{{else:}}
<ol>
{{for i in hosts:}}
<li>{{=A(i['HostName'], callback=URL('selection','getResults.load', vars=dict(clicked=i['HostName'])), target="monitoredDevice")}}</li>
{{pass}}
</ol>
{{pass}}
{{end}}
{{block right_sidebar}}
<div id="monitoredDevice">
</div>
{{end}}
控制器操作:
def getResults():
hostName = request.vars.clicked
# hostName = request.vars.hostNameSelected
print(hostName)
try:
task_status = scheduler.task_status(db.scheduler_task.task_name==hostName, output=True)
result = task_status.result
# create_compare_graph()
except(AttributeError): # Error is because there is no scheduler and therefore no status, need to set the values to 0
result = emptyTaskStatusResultsToZero()
try:
return dict(result)
except(TypeError): # There is a task scheduled however there is no run data as it has not been run before. Causes an error.
return emptyTaskStatusResultsToZero()
我认为视图中的= A链接有问题吗?
谢谢!
答案 0 :(得分:0)
如果没有返回任何内容,该方法只会阻止视图出错,因此我将所有值设置为零,以便视图有一些要呈现的内容。
def emptyTaskStatusResultsToZero():
return {'percent_diff_in': 0, 'percent_diff_out':0, 'now_avg_30mins_in': 0
, 'now_avg_30mins_out':0, 'prev_week_avg_30mins_in':0, 'prev_week_avg_30mins_out':0,
'percent_more':0,'percent_less':0, 'count':0}