expand arrays

Is there a way to expandObject except for an Array?
8 Replies
Daniel Thorp
Daniel Thorp3y ago
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
Mana3y ago
There's no way to identify arrays in that, so there probably are no good methods.
Calego
Calego3y 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
Daniel Thorp3y ago
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"
}
}
}
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Daniel Thorp
Daniel Thorp3y ago
I need it to be an actual array because I need it to work with the Array push/pop/filter/unshift/etc. methods
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Calego
Calego3y 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