0

How would I go about creating a graph like data structure in javascript? I want to have a link within the structure that points some where else within the structure.

Like in this example:

var MenuLayout = {
    home: {
        buttons: [{
            text: "Identify Tree",
            link: MenuLayout.treeid
        }, {
            text: "Plant"
        }, {
            text: "Information"
        }, {
            text: "Enter Tree"
        }]
    },
    treeid: {
        buttons: [{
            text: "Something Else"
        }]
    }
};

In this example I would like MenuLayout.home.buttons[0].link point to MenuLayout.treeid node. Is there a way to get it to point to that?

NOTE: I want this to work for an arbitrary order of declaration.

HSchmale
  • 1,838
  • 2
  • 21
  • 48
  • Lots of suggestions in that other questions. Everything is a workaround though, since it's not possible to do what you want to do. – Felix Kling Nov 12 '15 at 23:50
  • You should probably create separate classes for graph and nodes. This would solve the object-literal self reference issue. – djfdev Nov 12 '15 at 23:57

0 Answers0