GWT使用Django模板设置变量值 [英] GWT set variable values with Django templates
问题描述
我在GWT组中回答了一个非常类似的问题去年,所以你可能想看看那里。
正如你所说,这个想法是将这个数据嵌入到主机页面内,而不是触发应用程序初始化期间需要额外的GWT RPC请求。您可以:
-
将数据嵌入到主机页面的JavaScript变量中,并使用词典 class
这是一个简单的解决方案,特别是如果您的数据可串行化为字符串字典。您可以使用您选择的模板引擎将这些数据插入主机页面(Django's,Mustache,FreeMarker,JSP ...)。
-
嵌入一个GWT-RPC有效载荷在您的主机页面中,如这里和那里
这更好,如果您需要序列化整个对象图(这可能是您想要的Tree小部件,具体取决于其复杂性)。这就像一个标准的GWT-RPC请求,而不是在启动时发送HTTP请求,而是在您的主机页面中安装GWT-RPC响应。
I am using a tree control in my GWT application. The tree has different items based on the user logged in. One way to populate the tree would be to query the server from my GWT code to get a list of tree items. But since the items will always be shown would it not be better to include information regarding them in the page itself? I am looking for views to achieve this. Would it be possible to get a template engine like django to insert these values into GWT string variables at serving time? Then I can use these string variables to populate the tree. Or is there a better way to achieve this?
I answered a very similar question in the GWT group last year, so you might want to take a look there.
The idea, as you said, is to embed this data inside the host page, instead of firing an additional GWT RPC request during the app's initialization. You can:
Embed the data inside a JavaScript variable in your host page, and access it using the Dictionary class
This is a simple solution, especially if your data is serializable as a dictionary of strings. You could use the templating engine of your choice to insert this data in your host page (Django's, Mustache, FreeMarker, JSP...).
Embed a GWT-RPC payload inside your host page, as explained here and there
This is better if you need to serialize a whole object graph (which might be what you want for your Tree widget, depending on its complexity). It's like a standard GWT-RPC request, but instead of sending an HTTP request at startup, the GWT-RPC "response" would have been be embedded inside your host page when you serve it.
这篇关于GWT使用Django模板设置变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!