Ravi Ram
Ravi Ram

Reputation: 24488

JQuery Map get index

I am using the below code to get FILE OBJ > parse using jquery .map function. The code is working as designed, but I need to get the INDEX for each object.

        $.map($('.multiupload').get(0).files, function (file) {

alert(this.length);                             

$('#fileList')
    .append('<li><label>' + file.name + '</label><span><input name="tbDescription" type="text" id="' + file.name + '"></span>' + listitems + '<span class="btn btn-mini">remove</span></li>');

I need to get the file (index) value so I can add it to the html output.

alert(this.length);
always return a 0 no matter how many files I have selected.

If the user selects 3 files I want the html output to be

Who do I get the File index value from $.map($('.multiupload').get(0).files, function (file) ?

Upvotes: 2

Views: 6019

Answers (1)

Ravi Ram
Ravi Ram

Reputation: 24488

I figured it out. I was missing callback with the function call. See documentation : http://docs.jquery.com/Utilities/jQuery.map

jQuery.map( array, callback )

$('.multiupload').live('change', function () {
                $.map($('.multiupload').get(0).files, function (file, i) {
                    // return file.name;
                    alert(i);
                    $('#fileList').append('<li><label>' + file.name.toUpperCase() + '</label><span><input name="tbDescription" type="text" id="' + file.name + '"></span>' + listitems + '<span class="btn btn-mini">remove</span></li>');
                });

Upvotes: 1

Related Questions