简体   繁体   English

如何在Play Framework CRUD模块中过滤关联

[英]How to filter associations in Play Framework CRUD Module

Let's say I have a Cat class which contains a collection of Kittens. 假设我有一个Cat类,其中包含小猫的集合。 I want to be able to list the Kittens according to a given condition, for example, the principal's role. 我希望能够根据给定条件(例如,校长的角色)列出小猫。 So far, no problem at all, I resolved this issue with an @Before which adds the corresponding filter to the list view. 到目前为止,完全没有问题,我使用@Before解决了此问题,该方法将相应的过滤器添加到列表视图。

But now I want to change the edit page for the Cat, so that when it lists the Kittens (remember, in the edit view I can select the Kittens for the selected Cat), it brings only those available for the principal's role. 但是现在我想更改Cat的编辑页面,以便当它列出小猫时(请记住,在编辑视图中,我可以为选定的Cat选择小猫),它只带那些可用于主体角色的小猫。 But the default behavior is to retrieve all the Kittens from the database, and that's not what I want. 但是默认行为是从数据库中检索所有小猫,这不是我想要的。

Does anyone know how to achieve that? 有谁知道如何做到这一点?

Default CRUD module in Play is a basic CRUD which lacks a lot of functionality in several scenarios. Play中的默认CRUD模块是基本的CRUD,在某些情况下缺少很多功能。 The best approach is to download the code of the module (you have it in your local Play deployment, under "modules"), add it to your project as a custom module and modify it as much as you need. 最好的方法是下载模块的代码(您可以在本地Play部署中的“模块”下找到它),将其作为自定义模块添加到项目中,并根据需要进行修改。

In your scenario, simply go into the part that renders the List view and hack it to use the filters. 在您的方案中,只需进入呈现“列表”视图的部分,然后对其进行破解以使用过滤器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM