File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Recursively calls itself to get the nested param ids.
3
+ *
4
+ * @param {Object } checkbox Checkbox.
5
+ * @param {Array } allParamIds Used to build the ids array, by constantly pushing an id into it.
6
+ *
7
+ * @return {Array } allParamIds All param ids.
8
+ */
9
+ const getAllParamIds = ( checkbox = { } , allParamIds = [ ] ) => {
10
+ // Push the checkbox value(id) in allParamIds.
11
+ allParamIds . push ( checkbox . value ) ;
12
+
13
+ /**
14
+ * If child checkboxes exist, loop through each one of them,
15
+ * and recursively call getAllParamIds() to push ids from children.
16
+ */
17
+ const childCheckboxes = checkbox ?. children ?? { } ;
18
+ if ( Object . keys ( childCheckboxes ) . length ) {
19
+ Object . keys ( childCheckboxes ) . forEach ( ( key ) => {
20
+ getAllParamIds ( childCheckboxes [ key ] , allParamIds ) ;
21
+ } ) ;
22
+ }
23
+
24
+ return allParamIds ;
25
+ } ;
26
+
You can’t perform that action at this time.
0 commit comments