【问题标题】:Web2py URL callback hidden when clicked and loading ajax单击并加载 ajax 时隐藏 Web2py URL 回调
【发布时间】:2015-03-15 21:38:50
【问题描述】:

我一直在使用 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 链接有问题?

谢谢!

【问题讨论】:

  • 你能提供更多关于emptyTaskStatusResultsToZero的细节吗?

标签: ajax url web2py


【解决方案1】:

如果没有返回任何内容,该方法只是防止视图出现错误,因此我将所有值设置为零,以便视图可以渲染。

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}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-28
    • 1970-01-01
    • 1970-01-01
    • 2016-04-13
    • 1970-01-01
    • 2016-06-29
    • 2018-09-29
    • 1970-01-01
    相关资源
    最近更新 更多