GWT使用Django模板设置变量值 [英] GWT set variable values with Django templates

查看:123
本文介绍了GWT使用Django模板设置变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在GWT应用程序中使用树控件。该树根据用户登录的不同项目。填充树的一种方法是从我的GWT代码查询服务器以获取树项列表。但是,由于项目总是被显示出来,在页面本身中包含有关它们的信息不是更好吗?我正在寻找意见来实现这一点。是否可以获得像django这样的模板引擎,以便在服务时将这些值插入到GWT字符串变量中?然后我可以使用这些字符串变量来填充树。还是有更好的方式来实现这一点?

解决方案

我在GWT组中回答了一个非常类似的问题去年,所以你可能想看看那里。






正如你所说,这个想法是将这个数据嵌入到主机页面内,而不是触发应用程序初始化期间需要额外的GWT RPC请求。您可以:


  1. 将数据嵌入到主机页面的JavaScript变量中,并使用词典 class



    这是一个简单的解决方案,特别是如果您的数据可串行化为字符串字典。您可以使用您选择的模板引擎将这些数据插入主机页面(Django's,Mustache,FreeMarker,JSP ...)。


  2. 嵌入一个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:

  1. 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...).

  2. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆