Get item number in instance.data.xxx (list)

If I had instance.data.myFiles defined, which contained a list of fileObjects, how do you select a specific item in that list?

Doing a console.log(instance.data.myFiles[2]) for example doesn’t seem to work.
I wondered if there was a special way in Bubble to do this?

Having one file in the array/list shows me the bottom section (S for single)
Having multiple files in the array/list shows me the top section (M for multiple)

image

console.log(JSON.stringify(instance.data.myFiles))

Should help you read it better

Thanks @shawnmi6, unfortunately that just shows me the same but in double quotes

image

When you have a single file and are able to see the object in the console.log, right click on one of the key names (example “name”) and copy the path. What is that value?

So copying the “property path” of name like this

image

Populates name in the clipboard
If I do the same on size, it gives me size

Can you share your code snippet of putting these objects into an array?

sure 2 secs

Ok… I see what I’m doing wrong now, this is the portion that’s relevant.
I was just trying to put each file within the loop, into the variable but I’m not using .push method on the array and after rechecking it, I just realised I can probably use e.target.files

Need to clean a few things up

 // open file dialog
    var input = document.createElement('input');
    input.type = 'file';
    input.multiple = 'multiple';
    input.onchange = e => {
        
        for (i = 0; i < e.target.files.length; i++) {

            instance.data.selected_files += e.target.files[i];

        }
        
    }
    input.click();

Just changed it to this and it works as expected now.

 // open file dialog
    var input = document.createElement('input');
    input.type = 'file';
    input.multiple = 'multiple';
    input.onchange = e => {
        
        instance.data.selected_files = e.target.files;
        
    }
    input.click();

Which now shows me this so thank you for making me think!

image

1 Like