Search code examples
javascriptjquerybackbone.jsinputbackbone-views

Backbone - how to pass this.files on file input change event in backbone view


In normal html, I write like this:

<input id="input-upload-image" type="file" multiple onchange="handleFiles(this.files)">

In Backbone, I write like this to get the same functionality:

events: { 'change #input-upload-image': 'handleFiles' }

handleFiles: function () {}

My question is how to pass this.files to handleFiles function in Backbone.

P.S. I tried $(e.currentTarget).val(); but it return just one file even if I choose more than one file.


Solution

  • You can access files of input with the event parameter of the change listener

    handleFiles: function (e) { console.dir(e.currentTarget.files)}