How can I pass a file list to a bootbox callback?

2019-09-02 07:02发布

When my user try to upload several files, I trigger a bootbox modal to make him decide on 2 possible options. On the bootbox callback, I want to iterate over a list of file that I get from my file input. The problem is that my file list variable is empty in the callback.

Have a look at the code:

this.loadFiles = function(files){
    if (files.length>1){ //here, 'files' is populated
        bootbox.dialog({
          message: APi18n.__("media_warning_multiple_file_input_modal_message"),
          title: TAPi18n.__("media_warning_multiple_file_input_modal_header"),
          animate: true,
          buttons: {
                danger: {
                    label: TAPi18n.__('cancel'),
                    className: "btn-default",
                        },
                success: {
                    label: TAPi18n.__('media_warning_multiple_file_input_modal_ok_button'),
                    className: "btn-info",
                    callback: function() {
                        console.log(files); //here, 'files' is empty
                        _.each(files, function(file){
                       //etc.

How can I access to my files list in my bootbox callback?

1条回答
做自己的国王
2楼-- · 2019-09-02 07:29

May your files variable be altered "later on" in the scope of your loadFiles function? If so, you should move the alteration part after using it for your dialog:

this.loadFiles = function(files){
    if (files.length>1){ //here, 'files' is populated
        bootbox.dialog({
          message: APi18n.__("media_warning_multiple_file_input_modal_message"),
          title: TAPi18n.__("media_warning_multiple_file_input_modal_header"),
          animate: true,
          buttons: {
                danger: {
                    label: TAPi18n.__('cancel'),
                    className: "btn-default",
                        },
                success: {
                    label: TAPi18n.__('media_warning_multiple_file_input_modal_ok_button'),
                    className: "btn-info",
                    callback: function() {
                        _.each(currFiles, function(file){
                       //etc.
                       });
                       // <--- HERE
                    }
查看更多
登录 后发表回答