0

我正在查看此来源http://w2ui.com/web/demos/#!sidebar/sidebar-2

我可以通过以下方式添加文件夹:

$("#projectExplorer").w2sidebar({
                name: "projectExplorer",
                nodes: [
                    { id: projectDir, text: projectName, img: "icon-folder", expanded: false, group1: true,
                        nodes: [
                            { id: scriptsDir, text: "Scripts", img: "icon-folder", group1: true, expanded: false },
                            { id: shaderDir, text: "Shaders", img: "icon-folder", group1: true, expanded: false }
                        ]
                    }
                ]
            });\

但是,当我尝试动态添加以下内容时:

w2ui.sidebar.insert(parent, null, [
                    { id: currentFile, text: _files[i], img: "icon-page" }
                ]);

我收到错误:TypeError:无法读取未定义的属性“插入”

我不知道 w2ui.sidebar 是从哪里来的,但它在链接中上面的示例代码中有效,所以我认为它是库正在创建的一些全局变量,但显然在我的情况下它不存在导致错误,但没有线索关于现在该做什么。

4

1 回答 1

0

我相信你想要:

w2ui.projectExplorer.add(parent, { id: currentFile, text: _files[i], img: "icon-page" });

当您定义时,$("#projectExplorer").w2sidebar(您正在创建一个带有 ID 的 w2sidebar projectExplorer。该示例有效,因为他们定义了$("#sidebar").w2sidebar(.

于 2015-04-06T02:24:47.810 回答