LOEFD
Join ServerLeague of Extraordinary FoundryVTT Developers
development-basics
expand arrays
Is there a way to
expandObject
except for an Array?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": ""
}
Desired output:
[
["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]
There's no way to identify arrays in that, so there probably are no good methods.
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
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"
}
}
}
Message Not Public
Sign In & Join Server To View
I need it to be an actual array because I need it to work with the Array push/pop/filter/unshift/etc. methods
2 Messages Not Public
Sign In & Join Server To View
Ohhhh that's what I did now I remember
@arcanist 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