Render view while processing data

廉价感情. 提交于 2020-01-17 08:31:05

问题


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.

I'm doing it this way:

Controller

public Result showData() {
    List<Data> data = service.getProcessedData();

    return ok(views.html.data.render(data));
}

View

@(data: List[Data])

<!-- html code -->

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.


回答1:


Like I said in comments, I did not find a solution using Play.

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.



来源:https://stackoverflow.com/questions/44056366/render-view-while-processing-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!