存储全局变量

时间:2019-05-08 03:32:23

标签: javascript papaparse

我正在使用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);
    });
};

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

2 个答案:

答案 0 :(得分:1)

只需使用newHeader1 ='Size'

答案 1 :(得分:0)

为新列生成标题行的方式存在问题。爸爸希望每行具有相同的列名,但是通过指定newHeader1 = propString + "_Size"等,这意味着列名将不同。您可以为每个列名使用常量吗?例如。 newHeader1 = "Size"

相关问题