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

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

问题描述

有没有人使用extjs作为前端构建了一个grails应用程序?是否有任何陷阱或陷阱,你会分心?



默认情况下,格式的格式输出格式与extjs预期的完全不同,但这只是在grails端自定义JSON? / p>

解决方案

我正在使用Grails + ExtJS的组合,这很容易实现。对于网格的JSON输出可以通过在控制器中执行此操作来轻松实现:

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

这将产生Ext兼容JSON,如:

  {items:[{class:Book,id:1,title:Grails的最终指南,作者:Graeme Rocher,... 

这是一个关于如何初始化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}
});

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

  grails.converters.json.date ='javascript'

我还实现了网格过滤器插件的服务器端功能,各种组合框组合实现(具有远程自动完成),树形,窗体等。如果你想看到更多的示例代码,让我知道。



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


Has anyone built a grails app using extjs as the frontend? Are there any pitfalls or gotchas that you'd care to share?

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 customizing the JSON on the grails side?

解决方案

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 )
}

this will produce "Ext-compatible" JSON like:

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

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" }
});

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 (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 :-)

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

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