See this:
You can use this code, you need to loop through the table to get the child variable:
frm.set_df_property(frm.doc.tablefield, 'options', [...options], frm.doc, childtablefield, child.name)
Example:
for (let child of frm.doc.childtable) {
if (x) {
frm.set_df_property(child.parentfield, 'options', [1, 2, 3], frm.doc.name, 'tablefieldname', child.name)
} else {
frm.set_df_property(child.parentfield, 'options', [1, 4, 5], frm.doc.name, 'tablefieldname', child.name)
}
}
frm.refresh_field("childtable");