在sails.js中实时刷新网页

在我的项目中,我正在使用sails.js。 从test1.ejs我调用一个Web服务,然后调用另一个ejs(test2.ejs)使用res.view()。 现在android用户正在input一些影响数据库的值,需要实时反映在网页上。 我无法弄清楚如何使用sails.js来实现。 此外,我需要甚至显示android用户响应,同时刷新网页。 简而言之,我想要一个像股市一样的dynamic用户界面,在服务器上的任何变化都反映在前端。 我需要使用其他任何像angularjs?

如果我理解你的问题,你可以使用JavaScript接口。

你应该像这样创build类:

public class WebAppInterface { Context mContext; /** Instantiate the interface and set the context */ WebAppInterface(Context c) { mContext = c; } /** Show a toast from the web page */ @JavascriptInterface public void showToast(String toast) { Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show(); } } 

在这之后,你应该把这个接口连接到你的webview中,像这样:

 webView.addJavascriptInterface(new WebAppInterface(this), "Android"); 

现在你可以像这样从JS调用Java代码:

 <script type="text/javascript"> function showAndroidToast(toast) { Android.showToast(toast); } </script> 

或者像这样从Java调用JS代码:

 webview.loadUrl("javascript:window.showAndroidToast(\"Hello, World!\")"); 

更多信息可以在这里find: https : //developer.android.com/guide/webapps/webview.html