Is there an object like the one below in to a popupSearch menu?
I'm currently doing the stringify thing and then need to slice away the different symbols I don't want.
globalState['temporaryTimecode'] = {
tempName1 : "1:01:18:14.48",
tempName2 : "0:59:43:08.48"
}
// My current way of translating it in to an array of objects that works with the popupSearch. It's not pretty but it works.
var inputArray = []
var input = JSON.stringify(globalState['temporaryTimecode']).slice(1, -1).split(',').map(x => inputArray.push({
Name: x.split('":"')[0].slice(1),
Timecode: x.split('":"')[1].slice(0, -1),
name: x.split('":"')[0].slice(1) + '::' + x.split('":"')[1].slice(0, -1)
}))
var selectedInstance = sf.interaction.popupSearch({
items: inputArray,
columns: [
{
key: 'Name',
name: 'Name',
width: 20
},
{
key: 'Timecode',
name: 'Timecode',
width: 80
}
],
onCancel: 'Abort',
}).item;
globalState['temporaryTimecode'][selectedInstance.Name] = undefined
- Christian Scheuer @chrscheuer2020-08-20 12:28:00.471Z
I am not sure I get what you're trying to do or what you're trying to work around.
Jesper Ankarfeldt @JesperA2020-08-20 12:36:35.891Z
fair enough.
I tried to simplify the code. In my realworld scenario the
temporaryTimecode
is a globalState. I'm saving temp marker positions in to it like this:
globalState['temporaryTimecode'][event.props.presetName] = newValue
So if I take
globalState['temporaryTimecode']
I get a set of objects (temp marker names with a timecode as their value), as seen in the "temporaryTimecode" variable I would think.
I would like them to show in a popup search like below:So I need to "convert" the set of objects in to an array of objects, and thought there might be a better way
Jesper Ankarfeldt @JesperA2020-08-20 12:44:27.217Z
And when I select from the list, it "clears" the timecode for that preset by making it undefined.
I've that to the original post for clarity.- In reply toJesperA⬆:
Christian Scheuer @chrscheuer2020-08-20 12:46:08.678Z
Ah ok.
I'd do it like this:
const temporaryTimecode = { tempName1: "1:01:18:14.48", tempName2: "0:59:43:08.48" }; const items = Object.keys(temporaryTimecode).map(key => ({ name: key, timecode: temporaryTimecode[key], })); const selectedKey = sf.interaction.popupSearch({ items: items, columns: [ { key: 'name', name: 'Name', width: 20 }, { key: 'timecode', name: 'Timecode', width: 80 } ], }).item.name; const selectedTimecode = temporaryTimecode[selectedKey]; log(selectedTimecode);
Jesper Ankarfeldt @JesperA2020-08-20 13:00:05.829Z
Perfect as always. And so clean. It was the Objects keys trick I didn't know. Will adapt that more :D