KnockoutJS 像 Windows 资源管理器一样选择嵌套列表

发布于 2024-12-24 22:00:44 字数 167 浏览 0 评论 0原文

我已经从高处和低处搜索了以下问题的答案。

我有一个文件夹列表,我希望能够单击该文件夹并显示其子文件夹。

这个 JSfiddle 会更好地解释它,它几乎完整,但它扩展了所有文件夹

I have searched High and low for an answer to the following.

I have a list of folders and I want to be able to click on the folder and show its children.

This JSfiddle will explain it better, its nearly complete but it expands all folders

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

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

发布评论

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

评论(1

无人问我粥可暖 2024-12-31 22:00:44

发生这种情况是因为您正在为每个文件夹循环“selectedFolder”中的所有“链接”,而不仅仅是选定的文件夹!

这也意味着,如果您选择“Folder1”,则链接位于文件夹“link1”和“link2”上;如果您选择“Folder2”,则链接位于“link3”和“link4”上!

您需要在显示链接之前检查是否选择了当前文件夹,例如:

http://jsfiddle.net/ saurus/kJYsm/

请注意我如何

"with: $parent.selectedFolder" 

使用 an

"if: $parent.selectedFolder().folderName == folderName"

更改你的,并且我还添加了另一个 div 检查“$parent.selectedFolder”是否未定义,否则第一次运行时会发生错误。您可以通过其他方式进行操作:您可以简单地将“selectedFolder”设置为默认的虚拟文件夹,或者如果您不需要额外的标记,则可以使用模板注释。

另请注意,即使删除“with:”一切都会正常,因为现在“$data”是当前文件夹,而这正是我们所需要的。

希望这有帮助!

this happens because you are cycling all 'links' in 'selectedFolder' for every folder, not only the selected one!

this also means that the links are on BOTH folders "link1" and "link2", if you select "Folder1" OR "link3" and "link4" if you select "Folder2"!

you need to check that the current folder is selected before showing the links, something like:

http://jsfiddle.net/saurus/kJYsm/

note how I changed your

"with: $parent.selectedFolder" 

with an

"if: $parent.selectedFolder().folderName == folderName"

and I have also added another div checking that "$parent.selectedFolder" is not undefined, without it a error occurs on first run. you can do on other ways: you can simply set 'selectedFolder' to a default dummy folder, or you can use templating comments if you don't want the extra markup.

Note also that even removing the "with:" everything works, because now "$data" is the current folder, and this is exactly what we need.

hope this helps!

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