javascript - 如何将变量提取到 jquery 函数中?
问题描述
我使用文本文件的内容创建表格。现在,我正在尝试使用 jquery 动态表,我需要逐行添加最新数据。因此,我将使用“setInterval”,然后检查 data.length 并将旧大小与当前大小进行比较,然后尝试添加新行。
虽然我已经在 jQuery(全局)中定义了变量,但在使用它时它看起来像一个新变量。如何从函数中排除变量?
var data = [];
window.addEventListener("load", function() {
function editData() {
$.get("collection.txt", function(txt) {
$("#output").text(txt);
console.log(typeof txt);
textLen = txt.length;
text = txt.replaceAll('{', '[');
textReverse = text.replaceAll('}', ']');
removeHexa = textReverse.replace(/\d+:/gi, '');
removelast = removeHexa.replace(/\u0000/gi, '');
cleanSpace = removelast.replace(/\s/gi, '');
cleancommas = cleanSpace.replace(/,,],|],/gi, ']\n');
veri = cleancommas.replaceAll('\n[', '\n');
veri = veri.replaceAll(']\n', '\n');
veri = veri.replace('[', '');
dataArray = veri.split('\n');
dataArray.forEach(function(item) {
item_new = item.split(',')
data.push(item_new);
});
});
}
function anotherFunction() {
data.unshift("etc"); // I want to use here that I get variable from Jquery
}
// or ı can use here
data.unshift(" .. .. ");
}
解决方案
推荐阅读
- c# - 远程服务器返回错误 (404) 未找到。在 system.net.httpwebrequest.getresponse()
- symfony - Symfony + Forms,by_reference = true 和 CollectionType 字段中的 allow_add
- mysql - MySQL Workbench 中的 For 循环
- python - 通过 buildozer 将 py 文件编译为 apk 时出现问题
- django - 通过 Django 发送电子邮件时出现 SSL 错误
- python - 将字节转换为二进制字符串的简单方法是什么?
- c# - 如果 C# 项目具有 .Netframework 依赖项,是否可以将其构建为 .Netcore 应用程序
- android - Android Studio 3.5.2 离线设置错误:app@debug/compileClasspath
- php - DD 在嵌套的 foreach 循环中不起作用
- apache-camel - 如何在 Camel 中处理多个 CXF 端点?