如何过滤AG:选择?

发布于 2025-02-01 09:31:58 字数 312 浏览 2 评论 0原文

我是Grails和GSP的新手。我试图找到有关是否可能的文档 - 我发现了一个类似的问题,但无法成功应用它。

我有此G:选择语句:

<g:select name="users"  multiple="multiple"
     optionKey="id"
     optionValue="name"
     value="${user?.users*.id}"
     from="${user.getUsers()}"
/>

我想知道是否可以向此添加过滤器或条件。我只能选择在某个国家(用户。国家)的用户。

I am new to Grails and gsp. I tried to find documentation on if this was possible - I found a similar question but was not able to successfully apply it.

I have this g:select statement:

<g:select name="users"  multiple="multiple"
     optionKey="id"
     optionValue="name"
     value="${user?.users*.id}"
     from="${user.getUsers()}"
/>

I was wondering if it was possible to add a filter to this, or a condition. I can only select users that are in a certain country (users.country).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉态萌生 2025-02-08 09:31:58

我想知道是否可以向此添加过滤器或
条件。

这是。

看起来您在模型中具有用户属性,该对象是某些类的实例,该类别具有名为用户>的集合。

您的应用中的某些内容将用户放在模型中,可能是控制器操作。最佳实践是不要将很多逻辑嵌入GSP中,因此我建议控制器进行过滤,然后将合格对象放入单独的模型变量中,而GSP可以参考,而不是user.getusers() ,或者您可以创建一个自定义的GSP标签,该标签接受用户并生成select

I was wondering if it was possible to add a filter to this, or a
condition.

It is.

It looks like you have a user property in the model and that object is an instance of some class that has a collection named users.

Something in your app is putting user in the model, likely a controller action. Best practice is to not embed much logic in a GSP so I would recommend either the controller do the filtering and put the qualifying objects in a separate model variable that the GSP can reference instead of user.getUsers(), or you could create a custom GSP tag which accepts a user and generates the select.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文