expand arrays

Is there a way to expandObject except for an Array?
8 Replies
Daniel Thorp -uOttawa
My Form Data
{
"modes.0.0": "none",
"modes.0.1": "",
"modes.1.0": "initiative",
"modes.1.1": "initiative",
"modes.2.0": "name",
"modes.2.1": "name",
"modes.3.0": "selection",
"modes.3.1": "data.flags.ctg.group",
"modes.4.0": "players",
"modes.4.1": "players.*.id",
"modes.5.0": "actor",
"modes.5.1": "data.actorId",
"modes.6.0": "mob",
"modes.6.1": ""
}
{
"modes.0.0": "none",
"modes.0.1": "",
"modes.1.0": "initiative",
"modes.1.1": "initiative",
"modes.2.0": "name",
"modes.2.1": "name",
"modes.3.0": "selection",
"modes.3.1": "data.flags.ctg.group",
"modes.4.0": "players",
"modes.4.1": "players.*.id",
"modes.5.0": "actor",
"modes.5.1": "data.actorId",
"modes.6.0": "mob",
"modes.6.1": ""
}
Desired output:
[
["none", ""],
["initiative", "initiative"],
["name", "name"],
["selection", "data.flags.ctg.group"],
["players", "players.*.id"],
["actor", "data.actorId"],
["mob", ""]
]
[
["none", ""],
["initiative", "initiative"],
["name", "name"],
["selection", "data.flags.ctg.group"],
["players", "players.*.id"],
["actor", "data.actorId"],
["mob", ""]
]
I'm interested in hearing less messy solutions, but this seems to work:
Object.values(expandObject(temp1)).map(o => Object.values(o).map(o => Object.values(o)))[0]
Object.values(expandObject(temp1)).map(o => Object.values(o).map(o => Object.values(o)))[0]
Mana
Mana4y ago
There's no way to identify arrays in that, so there probably are no good methods.
Calego
Calego4y ago
I thought the foundry default expand object does this At least when my form data has keys with 0s and such like that it shows up as arrays
Daniel Thorp -uOttawa
It looks like this for me:
{
"modes": {
"0": {
"0": "none",
"1": ""
},
"1": {
"0": "initiative",
"1": "initiative"
},
"2": {
"0": "name",
"1": "name"
},
"3": {
"0": "selection",
"1": "data.flags.ctg.group"
},
"4": {
"0": "players",
"1": "players.*.id"
},
"5": {
"0": "actor",
"1": "data.actorId"
}
}
}
{
"modes": {
"0": {
"0": "none",
"1": ""
},
"1": {
"0": "initiative",
"1": "initiative"
},
"2": {
"0": "name",
"1": "name"
},
"3": {
"0": "selection",
"1": "data.flags.ctg.group"
},
"4": {
"0": "players",
"1": "players.*.id"
},
"5": {
"0": "actor",
"1": "data.actorId"
}
}
}
LukeAbby
LukeAbby4y ago
well that works with getProperty just fine asfik even if the underlying data looks silly
Daniel Thorp -uOttawa
I need it to be an actual array because I need it to work with the Array push/pop/filter/unshift/etc. methods
LukeAbby
LukeAbby4y ago
Ah just do Object.values() recursively for the ones you know are arrays then. which is what you're doing so
Calego
Calego4y ago
Ohhhh that's what I did now I remember @arcanistzed there's a method you can override in formapplication that isn't _updateObject which manipulates the form values provided to updateObject: _getSubmitData so i'd recommend doing whatever you come up with in there

Did you find this page helpful?