Grid Grid和Grails后端的ExtJS CRUD操作

时间:2013-05-23 01:45:19

标签: extjs

我是一个绝对的新手,并且一直在与ExtJS一起努力奋斗!我应该得到一个用户记录列表,并在Ext grid Panel上进行dipslay。我有一个ExtJS前端和Grails(Groovy控制器)后端。我已经提到过几个链接:

http://docs.sencha.com/extjs/4.0.7/#!/example/grid/row-editing.html
http://docs.sencha.com/extjs/4.0.7/#!/example/restful/restful.html
http://docs.sencha.com/extjs/4.0.7/#!/example/writer/writer.html

The api property ( or ) tag ( or )attribute ( I don't know what it is called ) helps me in getting the list of JSON objects to be displayed in the Grid. Also, when I select a row and click on Delete, the request is reaching the delete action in my controller. But my problems begins here: how do I make sure that:

1) the selected row is deleted from Database? How do I pass the identifier or something to controller so that it will delete the record?

2) When I add a row, how do I pass the field values to backend Controller?

Most of the code is same as given in the restful link above. For reference, this is my Datastore:

https://docs.google.com/document/d/1gQyLCt6xWXTm-OUgYu7hku47r5WcS0my5yPBSKj2B7I/edit?usp=sharing

1 个答案:

答案 0 :(得分:0)

如果您使用Rest代理,ExtJS将根据您指定的网址存根自动为您生成网址。因此,如果您的代理配置为指向以下内容:/ api / users,则会为以下4个操作生成以下网址:

  • 阅读:/ api / users(GET)
  • create:/ api / users(POST)
  • 更新:/ api / users / SomeIDFromTheUpdatedRecord(PUT)
  • 删除:/ api / users / SomeIDFromTheDeletedRecord(DELETE)

如您所见,每个请求的结束点完全相同(api / users),但对于PUT和DELETE,受影响记录的ID会自动包含在URL中。

当然,对于POST和PUT请求,您可以添加您想要发送到服务器的任何其他参数,但是当您通过商店配置的代理持久保存模型实例时,这将自动完成。 / p>