首页 > 解决方案 > 存储在全局变量中

问题描述

我正在使用 Papa Parse 解析本地 CSV 文件。

当我将更新的对象打印到控制台时,我让对象返回我根据某些条件应用的更改值。

我的问题是获取图像尺寸:宽度和高度。

下面是我的脚本;

var w;
var h;
let testString = "s2345232";
if (/^[s]\d+$/.test(testString) == true) {
    url = baseUrl + testString + suffix;
    getMeta(url, function(width, height) {
        w = width;
        h = height; 
        console.log(w, h); //works
    });  
}
console.log(w, h); // doesn't work
// Here is the function to retrieve the image data
function getMeta(url, callback) {
    var img = new Image();
    img.src = url;
    img.addEventListener("load", function() {
        callback(this.naturalWidth, this.naturalHeight);
    });
};

我做错了什么,我该如何解决?

标签: javascriptpapaparse

解决方案


只需使用 newHeader1 = 'Size'


推荐阅读