处理数据时渲染视图 [英] Render view while processing data
问题描述
我使用的是Play框架2.5.14,可以玩Java.
I'm on Play Framework 2.5.14, with play for java.
我有一个可加载和处理某些数据的服务,并且处理该数据需要很长时间.
I have a Service that loads and processes some data, and it takes a long time to process that data.
我正在这样做:
Controller
public Result showData() {
List<Data> data = service.getProcessedData();
return ok(views.html.data.render(data));
}
View
@(data: List[Data])
<!-- html code -->
但是当我转到页面时,它很空白,因为service.getProcessData()
花费的时间太长.函数完成后,将呈现视图.
But when I go to the page it is in blank a long time because service.getProcessData()
takes too long. When the function finish, then the view is rendered.
我需要加载视图,并在数据准备好后填充视图.
What I need is for the view to load and when the data is ready, fill the view.
推荐答案
就像我在评论中说的那样,我没有找到使用Play的解决方案.
Like I said in comments, I did not find a solution using Play.
我要做的是渲染视图,并在视图本身中用javascript/jquery调用ajax
请求以获取慢速数据.
What I do is to render the view, and in the view itself I call an ajax
petition in javascript/jquery to get the slow data.
希望这会有所帮助,这是我唯一喜欢的解决方案.
Hope this can help, it is the only solution that I liked.
这篇关于处理数据时渲染视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!