javascript - 存储在全局变量中
问题描述
我正在使用 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);
});
};
我做错了什么,我该如何解决?
解决方案
只需使用 newHeader1 = 'Size'
推荐阅读
- ios - 使用核心数据时冻结的 UI .mainQueueConcurrencyType
- git - Git:git log 中显示的提交的 SHA 与 PR 中的不同吗?
- c - 在 NASM 中无法正确计算平方根函数
- jenkins - 通过詹金斯作业运行时,如何使 JUnit 测试访问远程服务器文件夹?
- hive - Hive 有睡眠功能吗?
- android - 在 Android 项目中使用 Kotlin + progurad 时出现 ClassCastException
- python - 了解 pandas 合并中的“left_index”和“right_index”参数
- javascript - Laravel ajax 无法正常运行
- python - 合并列具有默认值和覆盖的数据框
- python - 如何格式化 scikit-learn 输出数据?