从 zope 目录调用派生的平面列表构建树结构,无需递归

发布于 2024-09-24 21:13:58 字数 164 浏览 2 评论 0原文

我拥有所有被查找的对象,以便为解释器提供父对象和对象子对象。我希望在不使用递归的情况下完成此操作,因为 zope 不喜欢这种传统的递归。

我将视图上下文设置为递归的根对象,以开始附加对象,然后迭代此过滤后的 intid/对象列表,查找将此对象作为父对象的对象。从那里我寻求起始代码,希望有人帮助我。

I have all objects which get looked up to provide interpreter with both parents objects and object subobjects. I hope to do this without recursion for zope not appreciating this conventional recursion.

I set the view context as root object for recursion to start attaching object on then iterate across this filtered list of intid/objects looking for object that has this object as parent. From there I seek starter code with hopes someone help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月染过的梦 2024-10-01 21:13:58

也许这个小技巧对你和对我都有用。

您可以通过 PathIndex (getPhysicalPath) 限制搜索结果,然后按字母顺序排序:

lst = context.Catalog.searchResults(path='/parentNodeId')
lst.sort()
print lst

您将看到类似这样的内容:

# /parentNodeId/
# /parentNodeId/folder/
# /parentNodeId/folder/file1.jpg
# /parentNodeId/folder/file2.jpg
# /parentNodeId/folder/file1.jpg
# /parentNodeId/folder2/
# /parentNodeId/folder3/
# /parentNodeId/folder3/file1.jpg
# /parentNodeId/folder3/file2.jpg

我认为从这个输出中您可以轻松构建树结构

Maybe this little trick will be usefull for you as it was for me.

You can restrict your search results by PathIndex (getPhysicalPath) and then just sort it alphabetically:

lst = context.Catalog.searchResults(path='/parentNodeId')
lst.sort()
print lst

You will see something like this:

# /parentNodeId/
# /parentNodeId/folder/
# /parentNodeId/folder/file1.jpg
# /parentNodeId/folder/file2.jpg
# /parentNodeId/folder/file1.jpg
# /parentNodeId/folder2/
# /parentNodeId/folder3/
# /parentNodeId/folder3/file1.jpg
# /parentNodeId/folder3/file2.jpg

I think from this output you can easy build a tree structure

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文