Meteor,Semantic UI进行大csv文件解析时的进度

时间:2016-09-23 06:26:41

标签: meteor semantic-ui papaparse

我试图在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
                    });
                });
            }
        });
    }
});

1 个答案:

答案 0 :(得分:0)

浏览器中的代码在单个线程中运行,因此即使更新进度变量,在文件解析完成之前,它也不会呈现给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?