Collection Query Problem

I found the problem for the code mentioned above in any case. The code runs before the text field is populated from the data-set. So you make sure the data-set has finished loading first before running the query. Like this:
$w.onReady( () => {
$w(“#myDataset”).onReady( () => {

I would still appreciated an example of doing a query on a referenced field in a collection.

Regards,
JD