getPersonWithRelationships
by Dovy Paukstys
HTML
<script src="http://rawgithub.com/rootsdev/familysearch-javascript-sdk/master/familysearch-javascript-sdk.js"></script>
<a id="run" href="#">Run</a>
<div id="output" />
JavaScript
function run() {
FamilySearch.getAccessToken().then(function() {
FamilySearch.getPersonWithRelationships('KW7S-VQJ',['persons']).then(function(response) {
var parents = new Array();
var spouses = new Array();
for (var r = 0, relationShipsLength = response.relationships.length; r < relationShipsLength; r++) {
var item = array();
item.id = response.relationships[r].id;
if (response.relationships[r].type == "http://gedcomx.org/ParentChild")
{
parents.push("Kiwi")
}
}
console.log(response);
console.log(response.persons);
console.log(response.relationships);
console.log(response.locations);
output('primary id',response.getPrimaryId());
output('Fathers');
outputRelatives(response.getFatherIds(), response);
output('Mothers');
outputRelatives(response.getMotherIds(), response);
var parentsIds = response.getParentsIds();
for (var p = 0, parentsIdsLength = parentsIds.length; p < parentsIdsLength; p++) {
output('parents', parentsIds[p]);
}
output();
output('Spouses');
var spouseIds = response.getSpouseIds();
outputRelatives(spouseIds, response);
for (var s = 0, spouseIdsLength = spouseIds.length; s < spouseIdsLength; s++) {
var spouseId = spouseIds[s];
output('Children of spouse', spouseId);
outputRelatives(response.getChildIds(spouseId), response);
}
});
});
}
function outputRelatives(ids, response) {
for (var i = 0, len = ids.length; i < len; i++) {
var id = ids[i];
output(' id', id);
output(' name', response.getName(id));
output();
}
}
FamilySearch.init({
app_key: 'WCQY-7J1Q-GKVV-7DNM-SQ5M-9Q5H-JX3H-CMJK',
environment: 'sandbox',
auth_callback: 'http://fiddle.jshell.net',
http_function: $.ajax,
deferred_function:...