在 grails 中使用 extjs 的经验? [英] Experience using extjs with grails?

查看:29
本文介绍了在 grails 中使用 extjs 的经验?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人使用 extjs 作为前端构建了 grails 应用程序?

Has anyone built a grails app using extjs as the frontend?

您有什么陷阱或陷阱想要分享吗?

Are there any pitfalls or gotchas that you'd care to share?

它看起来像grails默认输出的JSON格式,它与extjs期望的完全不同,但这只是在上自定义JSON的问题>grails 一边?

It looks like the JSON format output by grails by default it quite different from what extjs expects, but is it just a matter of customising the JSON on the grails side?

推荐答案

我经常使用 Grails + ExtJS 组合,它很容易实现.通过在控制器中执行以下操作,可以轻松实现网格的 JSON 输出:

I'm using the combination Grails + ExtJS a lot and it's quite easy to implement. The JSON Output for grids can be easily achieved by doing something like this in your controllers:

def list = {
   def books = Book.list(params)    
   render( [ items: books, totalCount: Book.count() ] as JSON )
}

这将产生与 Ext 兼容的"JSON,例如:

this will produce "Ext-compatible" JSON like:

{"items":[{"class":"Book","id":1,"title:"The Definitive Guide to Grails","author":"Graeme Rocher",...

这是一个关于如何初始化 JsonStore 的示例:

this is an example on how you should initialize the JsonStore:

var store = new Ext.data.JsonStore({
   url: '${createLink( action: 'list' )}',
   root: 'items',
   totalProperty: 'totalCount',
   fields: [ 'id','title','author','isdn', 'dateCreated' ],
   paramNames: { start : "offset", limit :"max", sort : "sort", dir : "order" }
});

处理日期值时,IMO 的最佳做法是为 JSON 转换器启用 Javascript 日期格式(即日期值将呈现为 new Date(123123123) 而不是默认值格式2009-04-16T00:00:00Z"),所以你不必关心日期格式或时区的东西.您可以通过在 grails-app/conf/Config.groovy 中进行配置来实现:

When dealing with Date values, it is IMO the best practice to enable the Javascript Date format for the JSON Converter (ie. date values will be rendered as new Date(123123123) instead of the default format "2009-04-16T00:00:00Z"), so you don't have to care about date format or timezone stuff. You can do this by configuring it in your grails-app/conf/Config.groovy:

grails.converters.json.date = 'javascript'

我还为网格过滤器插件实现了服务器端功能、组合框实现的各种组合(具有远程自动完成功能)、树、表单等.如果您想查看更多示例代码,请让我知道.

I've also implemented the server-side functionality for the grid filter plugin, various combinations of combo box implementations (with remote auto-completion), trees, forms etc. If you want to see more example code for that, let me know.

ExtJS 3.0(目前为 RC)与 Grails 集成得更好,因为 DataStores 提供了将数据发送回后端以进行持久化的选项.Ext.Direct 方法也提供了新的可能性:-)

ExtJS 3.0 (currently RC) integrates even better with Grails, as the DataStores provides the option to send data back to the backend to get persisted. The Ext.Direct approach provides new possibilities as well :-)

这篇关于在 grails 中使用 extjs 的经验?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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