//JSON Data
var listEmployees = { "employees": [{ "Id": 3, "Name": "David" }, { "Id": 2, "Name": "Adam" }, { "Id": 1, "Name": "Shan"}] };
var listSuper = { "funds": [{ "EmpId": 3, "FundName": "123 Super" }, { "EmpId": 2, "FundName": "XYZ Super" }, { "EmpId": 1, "FundName": "ABC Super"}] };
var listDetails = { "details": [{ "EmpId": 3, "Address": "123 Street", "Dob": "1995/07/21" }, { "EmpId": 1, "Address": "ABC Street", "Dob": "1983/06/21" }, { "EmpId": 2, "Address": "XYZ Street", "Dob": "1995/06/21"}] };
//Query to get all employees (and their details) whose Date of Birth is greater than 1990/01/01, ordered by Name
var employees =
$.list(listEmployees.employees)
.join(listSuper.funds, function (emp, superAnn) { return emp.Id == superAnn.EmpId; })
.join(listDetails.details, function (lastJoin, detail) { return lastJoin[0].Id == detail.EmpId; })
.where(function (joinedItem) { return new Date(joinedItem[2].Dob) > new Date(1990, 1, 1) })
.toList(true)
.orderBy(function (a, b) { return a[0].Name < b[0].Name ? -1 : a[0].Name > b[0].Name ? 1 : 0; })
.select(function (joinedItem) {
var item = {};
item.Id = joinedItem[0].Id;
item.Name = joinedItem[0].Name;
item.Super = joinedItem[1].FundName;
item.Address = joinedItem[2].Address;
item.Dob = joinedItem[2].Dob;
return item;
});
for (var i = 0; i < employees.length; i++) {
$("<li>"+employees[i].Id + "," + employees[i].Name + "," + employees[i].Super + "," + employees[i].Address + "," + employees[i].Dob+"</li>").appendTo('#list');
}
<ul id="list"></ul>
External resources loaded into this fiddle: