I'm developing a tool to create Nassi-Shneiderman diagrams online. The model for each diagram is simply an object literal, storing everything with unlimited possible children.
this then results in a view populated like the following:
Now if I want to add let's say a sequence into the while loop after the first sequence, I somehow have to add a child to the object between the two existing children. The order of an object's properties is not editable by default though and W3C says that one should not rely on the order of the properties because the can differentiate between browsers. I know I could store the object's order in an array, but then I'd have to rewrite the recursive loop which populates the view and so on..
Can I somehow manipulate the order of an object's properties? I don't mind using 3rd party libraries.
By "order" I mean the order an object's properties get iterated over using a for(prop in obj)
loop.
Here's an example of my data structure/object:
{
"procedure": {
"id": "content",
"child": {
"154": {
"class": "sequence",
"text": "json manually created in code",
"id": 154,
"contenteditable": "true"
},
"155": {
"class": "while",
"id": 155,
"child": {
"157": {
"class": "while-condition",
"text": "while JSON from File imported",
"id": 157,
"contenteditable": "true"
},
"158": {
"class": "while-body",
"id": 158,
"child": {
"159": {
"class": "sequence",
"text": "Sequence in a while loop",
"id": 159,
"contenteditable": "true"
},
"160": {
"class": "while",
"id": 160,
"child": {
"161": {
"class": "while-condition",
"text": "while parentNode.Whatever != FALSE",
"id": 161,
"contenteditable": "true"
},
"162": {
"class": "while-body",
"id": 162,
"child": {
"163": {
"class": "sequence",
"text": "Sequence even deeper nested",
"id": "163",
"contenteditable": "true"
}
}
}
}
}
}
}
}
},
"156": {
"class": "sequence",
"text": "Finish Procedure",
"id": 156,
"contenteditable": "true"
}
}
}
}