在后台启动 Rails 辅助方法,然后使用 ajax 更新页面上的相应元素
我有一个网页,它遍历各种列表。对于列表中的每个项目,我需要执行一些计算,并根据这些计算绘制图表。
然而,计算需要它自己的甜蜜时间,因此我想继续渲染页面的其余部分,而计算在后台进行。
从需求的角度来看,对我来说,ajax 似乎可以帮助我实现这个后台功能块,或者不能吗?
当函数返回其值时,我想将 ajax 引入图片中,并更新相应的 DIV 以填充图表。
我的困惑点 -
我不在这里处理控制器/操作。正在呈现的动作是索引。我得到了一些清单。对于该列表,我然后启动此计算。
或者,我可以将此计算调用插入索引操作本身,但随后我将面临一个挑战,即在所有计算完成之前索引操作不会开始渲染。
从概念上讲,我非常确定 Rails + ajax 组合可以让我实现这一目标。 只是没有通过这个得到我的可视化..有什么帮助吗?
I have a webpage, which iterates through a list of sorts. For each of the items in the list, I need to perform some computations, based on which I plot a graph.
However, the computation takes itw own sweet time, and therefore I want to continue rendering the rest of the page, while the computations go on in the background.
From the requirements perspective, to me, it looks like ajax can help me achieve this background functionality piece, or can it not ?
When the functions return with their values, I want to bring in ajax into picture, and update the respective DIVs to populate the chart.
my points of confusion -
I am not dealing with controller/actions here. the action being rendered is index. and i get some list back. for that list i then launch this computation.
alternatively, i can plug this computation call in the index action itself, but then i'd have the challenge of not having the index action start rendering till all the computation is done.
Conceptually, I am pretty certain rails + ajax combo would allow me to achieve this.
Just not getting my visualization through this.. any help ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否可以完全独立于索引进行计算,然后使用 ajax 进行访问?您可能会错过几毫秒的计算时间,但它可能会为您简化事情。
另外,这些数据需要多久计算一次?是否需要在每个页面加载时完成,或者可以每天/每周/每小时或其他什么方式完成?如果可以的话,您可以在 cron 作业中完成,然后通过 ajax 或直接通过索引调用结果。
Would it be feasible for you to do the computation wholly independently from the index then access with ajax? You might miss a few ms of computation time but it might simplify things up for you.
Also, how often does this data need to be computed? Does it need to be done on every page load or can it be done daily/weekly/hourly or whatever? If it can, you can just do it in a cron job and just call the results via ajax or directly through the index.