0

我有一个可以在线修改行的表。每行末尾都有一个提交按钮列。这很好用,因为我遍历域对象的支持列表,将每个对象放入一个表单中,然后以这种方式单独提交它们。

当我添加一列复选框以允许用户批量更新多行时,我的问题就出现了。批量更新操作的按钮在该表之外,也是每一行的表格。当我点击表外的批量更新按钮时,如何获取所选行的支持域对象?

我意识到我可能可以专门为复选框向域对象添加一个字段,但我不想这样做,因为它看起来很乱,而且只是我必须使用的 UI 的结果,而不是服务于功能目的。

提前感谢您的帮助,如果您需要更多信息,请告诉我!

托尼

4

1 回答 1

0
  1. Don't keep one form for each row, keep it as one big form.
  2. Give each checkbox the same 'name', and on the backend you can access it as a list.
    Example: <g:checkbox name="selectedRow" />
  3. Similarly give each input field in each column the same name also. For example, give all textboxes which take the input of age in all the rows the same name.
  4. Now on the backend all the column inputs can be accessed as groovy lists.
  5. Extract the checkbox inputs by doing 'params.selectedRow' (selectedRow was the name given to our checkboxes above)
  6. now in that list find the checkboxes which have value true, match the indexes of this checkbox list with the rest of the inputs, and update them.

I've tried to make this answer as detailed as possible, let me know if you didnt understand any part.

于 2012-08-14T13:20:10.637 回答