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

痞子三分冷 提交于 2019-12-13 07:38:01

问题


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:


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
                    }


来源:https://stackoverflow.com/questions/31457452/how-can-i-pass-a-file-list-to-a-bootbox-callback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!