javascript - How to use json_encode correctly? -
i'm trying display family tree. tool i'm using called javascript basic primitives. here can find more info it: http://www.basicprimitives.com/index.php?option=com_content&view=article&id=1&itemid=4&lang=en function displays every leaf of tree:
/** * displayleaf * displays leaves of family tree current individual , relatives */ function displayleaf($type, $individualid, $name, $dates, $gender, $bio, $avatar, $username, $relationships, $relationshipdates) { ?> var individualid = <?php echo json_encode($individualid); ?>, name = <?php echo json_encode($name); ?>, dates = <?php echo json_encode($dates); ?>, gender = <?php echo json_encode($gender); ?>, bio = <?php echo json_encode($bio); ?>, avatar = <?php echo json_encode($avatar); ?>, username = <?php echo json_encode($username); ?>, relationships = <?php echo json_encode($relationships); ?>, relationshipdates = <?php echo json_encode($relationshipdates); ?>, parentid = null, isvisible = true, itemtype = primitives.orgdiagram.itemtype.regular, placementtype = primitives.common.adviserplacementtype.auto; <?php if (!empty($type)) { ?> (var = 0; < items.length; i++) { if (items[i].id == individualid) { parentid = -1; } else { <?php if ($type == 'invisible aggregator') { ?> isvisible = false; if (items[i].relationship == relationships) { parentid = items[i].parent; placementtype = primitives.common.adviserplacementtype.left; items[i].parent = individualid; items[i].itemtype = primitives.orgdiagram.itemtype.adviser; (var j = 0; j < items.length; j++) { if (items[j].id.indexof("aggr") != -1) { if (items[j].id.indexof(relationships) != -1) { items[j].parent = individualid; items[j].itemtype = primitives.orgdiagram.itemtype.subadviser; } if (items[j].id.indexof(relationships) == -1) { if (items[j].parent != null) { } else { items[j].parent = individualid; items[j].itemtype = primitives.orgdiagram.itemtype.subadviser; items[j].placementtype = primitives.orgdiagram.adviserplacementtype.left; } } } } } else if (relationships.indexof(items[i].id) != -1) { parentid = items[i].id; itemtype = primitives.orgdiagram.itemtype.adviser; } <?php } if ($type == 'parent') { ?> if (items[i].relationship == relationships) { <?php $type = 'invisible aggregator'; $_individualid = $individualid.' aggr '; $this->displayleaf($type, $_individualid, $name, null, null, null, null, null, $relationships, null); ?> (var j = 0; j < items.length; j++) { if (items[j].id == <?php echo json_encode($_individualid); ?>) { parentid = items[j].id; isvisible = true; itemtype = primitives.orgdiagram.itemtype.adviser; } } } <?php } if ($type == 'currentindividual') { ?> if (items[i].relationship.indexof(individualid) != -1 && items[i].isvisible == false) { parentid = items[i].id; } <?php } if ($type == 'spouse') { ?> if (items[i].id == relationships) { <?php $type = 'invisible aggregator'; $_individualid = $individualid.' aggr '; $_relationships = json_decode($relationships).' '.json_decode($individualid); $this->displayleaf($type, $_individualid, $name, null, null, null, null, null, $_relationships, null); ?> (var j = 0; j < items.length; j++) { if (items[j].id == <?php echo json_encode($_individualid); ?>) { parentid = items[j].id; isvisible = true; itemtype = primitives.orgdiagram.itemtype.adviser; } } } <?php } if ($type == 'child') { $relationshiparr = explode(' ',json_decode($relationships)); ?> if (items[i].relationship == relationships && items[i].isvisible == false) { parentid = items[i].id; } if ("<?php echo $relationshiparr[0]; ?>".indexof(items[i].id) != -1 || items[i].id.indexof("<?php echo $relationshiparr[1]; ?>") != -1) { if (items[i].isvisible == false) { parentid = items[i].id; } } <?php } ?> } } items.push(new primitives.orgdiagram.itemconfig({ id: individualid, relationship: relationships, parent: parentid, isvisible: isvisible, title: name, description: dates, itemtype: itemtype, adviserplacementtype: placementtype, templatename: gender, image: avatar })); <?php } }
the function can called multiple times other functions have info of parents, children, spouses , function if need add invisible item tree , give custom layout. how tree formed. i've been trying pass php variables javascript using "" , working fine when i've decided start using json_encode , json_decode tree view disappeared. happens if statemens call function executed. why? doing wrong? how can use json_encode correctly in function above?
Comments
Post a Comment