No internet connection
  1. Home
  2. How to

Best way to get a set of objects in to a SF popupSearch list?

By Jesper Ankarfeldt @JesperA2020-08-20 12:10:57.220Z2020-08-20 12:44:42.241Z

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
Solved in post #5, click to view
  • 5 replies
  1. I am not sure I get what you're trying to do or what you're trying to work around.

    1. 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

      1. 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.

        1. In reply toJesperA:

          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);
          
          
          Reply2 LikesSolution
          1. Perfect as always. And so clean. It was the Objects keys trick I didn't know. Will adapt that more :D