【问题标题】:Meteor, Semantic UI Progress while big csv-file parsingMeteor, Semantic UI Progress while big csv-file parsing
【发布时间】:2016-09-25 20:53:29
【问题描述】:

我正在尝试解析 Meteor 应用程序中的大 csv 文件并使用 Semantic UI Progress 组件显示进度。但它会冻结并仅显示最终结果。

Template.ordersImport.events({
    'click button': function (e) {
        e.preventDefault();
        Papa.parse($('#importedFile')[0].files[0], {
            delimiter: ';',
            newline: '\n',
            header: true,
            fastMode: true,
            complete: function (result) {
                $('form').hide();
                $('#progress').show();
                var totalSize = result.data.length;
                _.each(result.data, function (item, index) {
                    var progress = (index + 1) / totalSize * 100;
                    $('#progress').progress({
                        percent: progress
                    });
                });
            }
        });
    }
});

【问题讨论】:

  • 使用工作线程并在step函数中更新UI。
  • 工作线程在 Meteor 中不起作用(harrison_papa-parse.js?hash=af12d7c...&papaworker:14 Uncaught ReferenceError: Package is not defined)
  • 你是对的。工作程序在 Meteor 包中不起作用,因为它全部捆绑到一个文件中,但可以修改库代码,使其内联工作程序函数(作为字符串),将其放在 public directory 或等待Meteor 支持的 WebWorker 构建目标(有人建议,不确定它是否会发生)。不过,您仍然可以使用 step 函数(如果您不使用 worker,它仍然会阻塞)。

标签: meteor semantic-ui papaparse


【解决方案1】:

浏览器中的代码在单个线程中运行,因此即使您更新了进度变量,它也不会在文件解析完成之前呈现到 UI。

在 UI 中进行冗长的处理不是一个好习惯 - 它会变得无响应,并且可能会导致浏览器崩溃,尤其是对于大文件。

我建议将文件传递到服务器,并在那里进行处理。

https://forums.meteor.com/t/how-to-use-web-worker/17511

如果您想在浏览器中继续处理,这个答案也可能会有所帮助

How to run an unblocking background task in a Meteor/JavaScript client?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-16
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 2016-03-29
    • 2015-11-14
    • 1970-01-01
    • 2023-03-24
    相关资源
    最近更新 更多