我有这个代码片段 - 我一直致力于将子页面添加到部门模块。它似乎在“if”语句之后丢失了变量。请参阅下面的代码。 *注意 - 一旦它到达“警报(部门)”,它就会给我一个“未定义”的消息。
这是调用函数的HTML / PHP。
<?php
function subPages($subpages, $parent){
foreach($subpages as $key => &$page){
$newParent = $page['id'];
//If the page's parent id matches the parent provided
if($page['parent_id'] == $parent)
{
//Echo out the link
echo '<li>';
echo '<a href="javascript:;" class="toggle collapsed">+</a>';
echo '<input type="checkbox" value="'. $page['id'] .'" id="list-check" name="subId[]" />';
echo '<a class ="subpage-link" href="javascript:;" onclick="editSubpage(\'popup\','.$page['id'].')">'.$page['title'].'</a>';
echo '<a href="javascript:;" class="add-subpage-button" onclick="addSubpage(\'popup\','. $page['department_id'] .', ' . $page['id'] .')">Add Subpage</a>';
//Set the page as the new parent
$newParent = $page['id'];
//Remove page from array
unset($subpages[$key]);
//Check the rest of the array for children
echo '<ul class="tier">';
subPages($subpages, $newParent);
echo '</ul>';
echo '</li>';
}
}
}
?>
<div class="tab-container">
<div class="box-title">
<h3>Subpages</h3>
</div>
<div id="first_box" class="box-content">
<div class="sbs-table-document">
<div class="title-name">
<input type="checkbox" id="check_all" title="Check All" onClick="toggle(this, 'subId[]');" />Title
</div>
</div>
</div>
<ul class="ads-content subpages">
<div class="subpage-content-container">
<input type="hidden" name="id" id="id" value="<?=$this->department->id?>" />
<?php subPages($this->subpages->toArray(), 0) ?>
</div>
</ul>
<a href="javascript:;" class="add-newsubpage-button" onclick="addSubpage('popup',<?= $this->department->id ?>)">Add New Subpage</a>
<a href="javascript;:" class="delete-subpage-button" onclick="removeSubpage('popup',<?= $this->department->id ?>);return false;">Remove Selection</a>
这是调用的AJAX函数。
function addSubpage(type, department, parent){
if(type == 'popup'){
$.ajax({
url:'/departments/admin-departments/subpage/parent_id/'+parent+'/department_id/'+department,
success:function(data){
displayPopup(data);
$('#title').focus();
wysiwyg();
}
});
}
else{
alert(department);
var str = $('#subpage').serialize();
$.ajax({
url:'/departments/admin-departments/subpage/',
type:'post',
data:str,
success:function(data){
successPopup();
window.location.href = "/departments/admin-departments/department/id/1/#tab2";
}
});
}
}
有关为何发生这种情况的任何想法?
谢谢,