Groovy在Grails列表 - 不工作? [英] Groovy on Grails list - not working?

查看:133
本文介绍了Groovy在Grails列表 - 不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从列表中删除元素不起作用,这不会产生任何影响感。我是否缺少处理Grails域对象列表特有的特殊语义?

Removing an element from a list isn't working, which doesn't make any sense. Am I missing some special semantics peculiar to dealing with a Grails domain object list?

在控制器中:

def userCreate = {
    def workgroupInstance = new Workgroup()
    workgroupInstance.manager = authUserDomain
    flash.message = User.list().toString()
    def usersWithoutThisOne = User.list() - authUserDomain
    flash.message = flash.message + "removed ${authUserDomain}, new list is ${usersWithoutThisOne}"
    return ['workgroupInstance':workgroupInstance, 'users':usersWithoutThisOne]
}

结果在闪存中显示。消息

Results in this being displayed in flash.message


[boogie,toogie,choogie,cookie]删除了boogie,新的列表是[boogie,toogie,choogie,cookie]

[boogie, toogie, choogie, cookie]removed boogie, new list is [boogie, toogie, choogie, cookie]


推荐答案

如果您打算永久地从工作组中删除用户,那么您需要使用grails < a href =http://grails.org/do c / latest / ref / Domain%20Classes / removeFrom.htmlrel =nofollow noreferrer> removeFrom 函数可以去掉存储在具有多关联的类中。

If you intend to remove the user from the workgroup permanently, then you need to use the grails removeFrom function to get rid of classes that are stored in a has many association.

这篇关于Groovy在Grails列表 - 不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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