SeedCode Logo


fmxj.js
a JavaScript approach to FileMaker Custom Web Publishing™

gh LogoDownload on GitHub

nestObjects(parentArray, childArray, childName, predicates)

Nest one array of objects into another as a property a SQL like Join.

parentArray
Type: Array of Objects
An Array of Objects that will be the parent objects and have the child array nested in them.
childArray
Type: Array of Objects
An Array of Objects to be nested into the above parent objects.
childName
Type: String
The name of the property of the child array in the parent object.
predicates
Type: Object
An object specifying the match keys to join parent and child objects. Only equijoin matches supported.
example 1
Call Contacts and Contact Info in separate calls with no portals on the layouts, then stitch together in JS. Compare to example 4 in the postQueryFMS() section where Contact Info is gathered via Portal. This operation tests a little bit slower overall, but the footprint on the server is smaller, so should scale better with multiple users. You also may not need nest them all at once and right away like in this example.

var contacts = [];
var q1 = fmxj.findRecordsURL("Contacts", "ContactsNoPortal");
var q2 = fmxj.findRecordsURL("Contacts", "ContactInfo");
function writeDownload(n){
	document.getElementById("nestResult").innerHTML +=  n + " bytes downloaded" ;
} ;
function updateContacts(js){
	function updateContactInfo(js){
		fmxj.nestObjects(contacts, js, "Contacts", {"parentKey1": "id", "childKey1": "id_Contact"});
		document.getElementById("nestResult").innerHTML += JSON.stringify(contacts,null, 4 );
	};
	fmxj.postQueryFMS(q2, updateContactInfo, null, relay);
	contacts = js;
};
fmxj.postQueryFMS(q1, updateContacts, writeDownload, relay);
}
};