我正在尝试使用scandir来显示特定目录中列出的文件夹的选择列表(工作正常)但是,我还需要将子文件夹(如果有的话)添加到我的选择列表中.如果有人能帮助我,那就太好了!
这是我想要的结构:
<option>folder 1</option>
<option> --child 1</option>
<option> folder 2</option>
<option> folder 3</option>
<option> --child 1</option>
<option> --child 2</option>
<option> --child 3</option>
Run Code Online (Sandbox Code Playgroud)
这是我从该线程获得的代码(仅显示父文件夹)(使用scandir()查找目录中的文件夹(PHP)):
$dir = $_SERVER['DOCUMENT_ROOT']."\\folder\\";
$path = $dir;
$results = scandir($path);
$folders = array();
foreach ($results as $result) {
if ($result == '.' || $result == '..') continue;
if (is_dir($path . '/' . $result)) {
$folders[] = $result;
};
};
Run Code Online (Sandbox Code Playgroud)
^^但我需要它来显示子目录..如果有人可以帮助,那就太好了!:)
编辑:忘了说我不想要文件,只有文件夹..
我想在再次填充之前从我的 xml 文件中删除所有子项(或创建更新,但这似乎更难)。所以我所做的是
$file = "data.xml";
$xml=simplexml_load_file($file);
$teller=0;
foreach( $entries as $entry ) {
foreach ($xml->xpath('//concerts') as $desc) {
if($teller == 0)
{
$lol=$desc->children();
unset($lol);
}
$concert = $desc->addChild( 'concert' );
$concert->addChild( 'artist', array_shift( $entry ) );
$concert->addChild( 'location', array_shift( $entry ) );
$concert->addChild( 'date', array_shift( $entry ) );
$teller++;
}
}
file_put_contents($file, $xml->asXML());
Run Code Online (Sandbox Code Playgroud)
但这并不能消除任何东西,对我做错了什么有什么想法吗?
我不知道如何做到这一点
我有
<div class="a parent">
<div class="child">
</div>
</div>
<div class="b parent">
<div class="child">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我想要这样的东西(在伪代码中)
$(".parent").mousemove(function(){
select the `.child` which is the child of this div
})
Run Code Online (Sandbox Code Playgroud)
因此,当.a它悬停在它上面时,它将.child仅选择一个,并且当.b它悬停在它上面时将.child仅选择b
这应该涉及this或$this或$(this)类似的东西..但它令人困惑,我不知道在哪里阅读它
我有html代码:
<div id="all">
<div id="1">
<div id="1-1">
</div>
<div id="1-2">
</div>
</div>
<div id="2">
<div id="2-1">
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我的JQuery代码中有一处:
var obj = jQuery("#1-2");
Run Code Online (Sandbox Code Playgroud)
我想检查他父母的哪个孩子(相对于他的父母)是obj(在这种情况下,它应该为第二个索引返回1).
我试过(没有结果):
alert(obj.index());
Run Code Online (Sandbox Code Playgroud) 我有一个带有各种嵌套无序列表的导航栏。我需要做的是计算每个 UL 的子级并设置一个包含最高计数数字的变量。
虽然我认为我可以使用 for/while 循环来做到这一点,但我不太确定如何去做。
该脚本将:
谢谢你的帮助!
我想稍后迭代Treeview中的数据.然后我希望能够对它进行整理.
from tkinter import *
from tkinter.ttk import *
import pickle
root = Tk()
def treeData(event):
children = tree.get_children()
print(children)
entry = StringVar()
a = Entry(root, textvariable=entry)
a.grid(column=0,row=0)
a.bind("<Key>", function)
file_data = []
file = open('data.dat', 'rb')
while True:
try:
file_data.append(pickle.load(file))
except EOFError:
break
file.close()
column_names = ("Column 1", "Column 2")
tree = Treeview(root, columns=column_names)
tree['show'] = 'headings'
for x in file_data:
a = tree.insert('', 'end', values=x)
for col in column_names:
tree.heading(col, text=col)
tree.grid(column=0, row=1)
Run Code Online (Sandbox Code Playgroud)
在我打印(子)时称为'treeData'的函数中,它输出一个类似于此的列表 - ('I001','I002','I003','I004')
我希望有人知道如何将这些数据转换成实际显示在Treeview行中的内容?
谢谢,
我有兴趣绑定动态生成的div的所有子级的单击事件。
自 1.7 起绑定
$(staticAncestors).on(eventName, dynamicChild, function() {...
example:
$('body').on('click','.myDiv', function() {...
Run Code Online (Sandbox Code Playgroud)
使用 * 作为选择器绑定到所有元素
$('.myDiv').on('click', '*', function() {...
Run Code Online (Sandbox Code Playgroud)
如何将 * 绑定到动态生成的div?
已经在jsfiddle中复制了我的项目。
注意:在 Ahmad 的 jsfiddle (请参阅第一个答案)中,子单击事件可以在包含或不包含*在单击选择器中的情况下工作。*在我的 jsfiddle 中,如果您单击 PARENT div,我的示例可以正常工作(当不是时),但单击 CHILD 元素(图像和文本标题)则不行。现在,将 * 添加到我的示例中,但没有任何效果...
我有两个不同的组件,它们扩展了一个通用组件。
AComponent extends BaseComponent {}
BComponent extends BaseComponent {}
Run Code Online (Sandbox Code Playgroud)
第三个组件具有 ng-content。
<wrapper>
<a-component></a-component>
<b-component></b-component>
</wrapper>
Run Code Online (Sandbox Code Playgroud)
不幸的是,这些组件在下面的场景中不可见。
WrapperComponent {
@ContentChildren(BaseComponent) components;
}
Run Code Online (Sandbox Code Playgroud)
我不想创建具有特定类型(Acomponent、BComponnet)的ContentChild。
我将一个 children 作为函数传递,返回React.ReactNode到 Provider HOC,如下所示:
<Provider variables={{ id: "qwerty" }}>
{data => (
<ExampleComponent data={data} />
)}
</Provider>
Run Code Online (Sandbox Code Playgroud)
这是提供程序组件示例代码:
type Props = {
id: string;
children: any; // What type should be put here?
};
const Provider: React.SFC<Props> = ({ id, children }) => {
const { data, loading, error } = useQuery<req, reqVariables>(query, {
variables: { id }
});
if (loading) return "Loading...";
if (error) return "Error";
if (!data) return "No data";
return children(data);
}
Run Code Online (Sandbox Code Playgroud)
如果我没有为 指定任何类型 …