在 ActiveAdmin 上级联自定义过滤器 [英] Cascading custom filter on ActiveAdmin
本文介绍了在 ActiveAdmin 上级联自定义过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 ActiveAdmin 上创建级联过滤器,但我不太确定如何去做.
I am trying to create a cascading filter on ActiveAdmin, and I am not quite sure how to go about it.
我有三个模型,它们具有连续的belongs_to/has_many关系,例如A有很多B,B有很多C.
I have three models that have successive belongs_to/has_many relationships, e.g. A has many B's, and B has many C's.
我可以创建如下三个过滤器,它们都可以工作,但我想要做的是根据 A 中的选择限制 B 集合.
I can create three filters like the following, and they work, but what I want to do is to limit B collection based on choice in A.
filter :b_a_name, :as => :select, :collection => A.map(&:name)
filter :b_name, :as => :select, :collection => B.map(&:name)
filter :year
无论如何要在 ActiveAdmin 上完成此操作?
Is there anyway to accomplish this on ActiveAdmin?
提前感谢您的帮助!
推荐答案
你可以使用 javascript 来完成这样的事情,即
You can accomplish something like this using javascript, i.e.
- 在
b_a_name
上监听更改事件 - 使用
b_a_name
和 向端点发出 ajax 请求 - 在成功回调中为
b_name
返回相应选项的 JSON 数组 - 用数组中的选项替换
b_name
的选择选项
- Listen to the change event on
b_a_name
- Make an ajax request to an endpoint with the selection in
b_a_name
with - Return an JSON array of the corresponding options for
b_name
in your success callback - Replace the select options for
b_name
with options in array
这篇关于在 ActiveAdmin 上级联自定义过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文