0

I'm looking at this source http://w2ui.com/web/demos/#!sidebar/sidebar-2

I'm able to add folders via:

$("#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 }
                        ]
                    }
                ]
            });\

However, when I then try to dynamically add with the following:

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

I get the error: TypeError: Cannot read property 'insert' of undefined

I have no ideas where w2ui.sidebar is coming from but it works in the example code above in the link so I figure it's some global variable the library is creating but clearly it's not there in my case which leads to the error, but no clue on what to do now.

user441521
  • 6,942
  • 23
  • 88
  • 160

1 Answers1

0

I believe you want:

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

When you define $("#projectExplorer").w2sidebar( you're creating a w2sidebar with the ID projectExplorer. The example works because they defined $("#sidebar").w2sidebar(.

rob05c
  • 1,223
  • 1
  • 9
  • 18