现在需要使用checkbox进行两个复选框列表的联动显示,假如有两个复选框列表要显示两个结果集。
A复选框列表显示数组a:
[
{id:'1',name:'A'},
{id:'2',name:'B'},
{id:'3',name:'C'}
];
B复选框列表显示数组b:
[
{parentId:'1',childName:'a'},
{parentId:'1',childName:'b'},
{parentId:'2',childName:'c'},
{parentId:'2',childName:'d'},
{parentId:'3',childName:'e'}
];
Note: The parentId in array b corresponds to the id in array a
Now I want to click on an item in the A checkbox list, the B checkbox list will display the record corresponding to the parentId according to the id value checked in the A checkbox list, and all records will be checked by default. .
Is there any good method? I am a novice. It is best to have codes for reference. Thank you everyone!
Only provide ideas
Listen to the change event of A. When A changes, get its value and then display the corresponding B.
By default, all checkbox elements of B are not displayed, display:none, and a data attribute is tied to each checkbox of B to distinguish the corresponding value of A. Then just change the display attribute of the checkbox corresponding to B when A changes.
Thank you both for your answers. I will post the code for reference and communication if necessary