Jquery“得到它”从递归PHP函数获取递归值

时间:2018-04-26 05:15:09

标签: javascript php jquery html recursion

我有这个PHP脚本,可以从我的路径中读取和打印我的目录。这个脚本运行正常。问题是jquery“get id”正在从这个打印结果中找出“recusive value”。我不知道它是如何发生的,但他正在从PHP递归功能创建的“所有循环”中获取值。它是一个简单的“默认”递归php函数:

<?php
function listIt($path) {
$items = scandir($path);

foreach($items as $key => $item) {
    if($item != "." and $item != ".." and $item !=".git" ) {
        if (is_file($path ."\\". $item)) {
            // nothing here
        } else {
            // the recursive item is here
            echo "<div  id='".$key.$path."/".$item."' class='togleFolder' togleFolder' style='padding-left: 25px'>";
                echo $item;
                listIt($path ."\\". $item);
            echo "</div>";
        }
    }
  }
}
echo "<div style='padding-left: 10px'>";
listIt(getcwd());
echo "</div>";
?>

Jquery脚本更简单:

<script type="text/javascript">
$(document).ready(function(){
    $(".togleFolder").click(function(){
        let myId= $(this).attr("id");
        console.log ("myId: "+myId);
    });
});

最后是HTML输出:

<div style="padding-left: 10px">
	<div id="3C:\Apache24\htdocs\FuryJson/My-Models" class="togleFolder" style="padding-left: 25px">My-Models</div>
	<div id="5C:\Apache24\htdocs\FuryJson/app" class="togleFolder" style="padding-left: 25px">
	app<div id="2C:\Apache24\htdocs\FuryJson\app/Http" class="togleFolder" style="padding-left: 25px">
	Http<div id="2C:\Apache24\htdocs\FuryJson\app\Http/Controllers" class="togleFolder" style="padding-left: 25px">
Controllers</div>
<div id="3C:\Apache24\htdocs\FuryJson\app\Http/Request" class="togleFolder" style="padding-left: 25px">
Request</div>
</div>
</div>
<div id="9C:\Apache24\htdocs\FuryJson/dump" class="togleFolder" style="padding-left: 25px">
dump</div>
<div id="15C:\Apache24\htdocs\FuryJson/open-iconic" class="togleFolder" style="padding-left: 25px">
	open-iconic<div id="7C:\Apache24\htdocs\FuryJson\open-iconic/font" class="togleFolder" style="padding-left: 25px">
	font<div id="2C:\Apache24\htdocs\FuryJson\open-iconic\font/css" class="togleFolder" style="padding-left: 25px">
css</div>
<div id="3C:\Apache24\htdocs\FuryJson\open-iconic\font/fonts" class="togleFolder" style="padding-left: 25px">
fonts</div>
</div>
<div id="8C:\Apache24\htdocs\FuryJson\open-iconic/open-iconic-master" class="togleFolder" style="padding-left: 25px">
	open-iconic-master<div id="7C:\Apache24\htdocs\FuryJson\open-iconic\open-iconic-master/font" class="togleFolder" style="padding-left: 25px">
	font<div id="2C:\Apache24\htdocs\FuryJson\open-iconic\open-iconic-master\font/css" class="togleFolder" style="padding-left: 25px">
css</div>
<div id="3C:\Apache24\htdocs\FuryJson\open-iconic\open-iconic-master\font/fonts" class="togleFolder" style="padding-left: 25px">
fonts</div>
</div>
<div id="9C:\Apache24\htdocs\FuryJson\open-iconic\open-iconic-master/png" class="togleFolder" style="padding-left: 25px">
png</div>
<div id="10C:\Apache24\htdocs\FuryJson\open-iconic\open-iconic-master/sprite" class="togleFolder" style="padding-left: 25px">
sprite</div>
<div id="11C:\Apache24\htdocs\FuryJson\open-iconic\open-iconic-master/svg" class="togleFolder" style="padding-left: 25px">
svg</div>
<div id="12C:\Apache24\htdocs\FuryJson\open-iconic\open-iconic-master/webp" class="togleFolder" style="padding-left: 25px">
webp</div>
</div>
<div id="10C:\Apache24\htdocs\FuryJson\open-iconic/png" class="togleFolder" style="padding-left: 25px">
png</div>
<div id="11C:\Apache24\htdocs\FuryJson\open-iconic/sprite" class="togleFolder" style="padding-left: 25px">
sprite</div>
<div id="12C:\Apache24\htdocs\FuryJson\open-iconic/svg" class="togleFolder" style="padding-left: 25px">
svg</div>
<div id="13C:\Apache24\htdocs\FuryJson\open-iconic/webp" class="togleFolder" style="padding-left: 25px">
webp</div>
</div>
<div id="17C:\Apache24\htdocs\FuryJson/routes" class="togleFolder" style="padding-left: 25px">
routes</div>
</div>

<div id="9C:\Apache24\htdocs\FuryJson/dump" class="togleFolder" style="padding-left: 25px">dump</div>

所以它给了我很多递归值而不是唯一的值。 对不起,如果我没有说清楚,那是因为这是一个非常难的问题。谢谢

0 个答案:

没有答案