我正在使用https://github.com/sferik/rails_admin来处理我的管理界面.
可以根据此模型中存在的当前列(id,created_at等)过滤模型.
我希望能够为关联添加自定义过滤器.
例如:
当我在探索"城镇"模型时,我希望能够只显示有一个或多个项目的城镇.
我可以通过向城镇添加一个新列来实现这一点,将has_projects称为布尔值,当有一个或多个项目关联时,它将设置为true,但我觉得必须有一种更清晰的方法来制作自己的自定义过滤器?
如何检查父母section是否有另一个div具有特定数据属性的"孩子" ?这是我要做的事情:
if ($("#parent").children().data("child-nr").contains("1") == true) {
$("#parent").css('background-color', 'green');
}
else {
$("#parent").css('background-color', 'red');
}Run Code Online (Sandbox Code Playgroud)
div {
width: 50px;
height: 50px;
background-color: lightblue;
float: left;
margin: 5px;
text-align: center;
vertical-align: middle;
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<section id="parent">
<div data-child-nr="1"><p>N° 1</p></div>
<div data-child-nr="2"><p>N° 2</p></div>
<div data-child-nr="3"><p>N° 3</p></div>
</section>Run Code Online (Sandbox Code Playgroud)