gpt4 book ai didi

javascript - 数组 VBScript 到 JavaScript

转载 作者:行者123 更新时间:2023-12-02 17:19:10 25 4
gpt4 key购买 nike

我有一个经典的 ASP 网站,我们采用 Flash 组件来生成图表,以通过 JavaScript 库合并此功能。

在同一页面 ASP 上,我们读取文本文件,数据保存在数组中,并且这些数据必须传递给 javascript 函数。该代码不是函数,因为根据所选的菜单,会读取不同的文件。这是一个非常广泛的代码。

 <%
···

ReDim LisOp (numop)

ReDim Lisco (numop)

ReDim LisVo (numop)

aux = options
for i = 1 to numop
p = InStr (aux, ",")
if p> 0 Then
LisOp (i - 1) = Left (aux, (p - 1))
Right aux = (aux, (Len (aux) - p))
else
LisOp (i - 1) = aux
aux = ""
end if
Next
···
%>

在这些变量 LisOp、Lisco、LisVo 中我们有数据。问题是当我想将此信息传递给 javascript 时:

<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<META HTTP-EQUIV = "refresh" CONTENT = "<% = TieRefresco%>">
<script type="text/javascript" src="http://www.google.com/jsapi"> </ script>
<script language="JavaScript">

google.load ('visualization', '1 ', {' packages': ['table', 'corechart']});
google.setOnLoadCallback (draw);

function draw () {
var options = {title:'',
legend: {position: "none"},
hAxis: {textstyle: {color: 'black', fontName: 'Arial Black', size: 16}}
};

// Create data table object
var google.visualization.DataTable datat = new (); / / DataTable Roles

// Define columns
datat.addColumn ('string', '<% = tOpciones%>'); / / Implicit domain column.
datat.addColumn ('number', '<% = tVotos%>'); / / Implicit data column.
datat.addColumn ({type: 'string' role: 'style'});
datat.addColumn ({type: 'string' role: 'annotation'});

for (var i = 0; i << numop%% => -1, i + +) {
datat.addRow (['OP1', 450, 'color: green', '450 ']);
}
···
</ Script>
</ HEAD>
<BODY>
···

在示例中,我为函数 addRow 保留了固定值,但我需要传递在 Visual Basic 脚本“LisOp、LisVo、LisCo”中创建的数组。固定值运行完美。然后我放置了我尝试过但尚未将数组值传递给函数 addRow 的代码示例:

我尝试了VBArray(arrayObj) toArray()函数;但它给了我一个错误,我没有制作图形:

 var arrayObj;
var jsArray;
arrayObj = LisOp
jsArray = VBArray (arrayObj) toArray ().;

for (var i = 0; i << numop%% => -1, i + +) {
datat.addRow ([jsArray[i], 450, 'color: green', '450 ']);
}

我尝试在draw()函数中为VBScript创建循环,但不起作用:

<% For i = 0 to numop%>
datat.addRow ([<%=LisOp(i)%>, <%=LisVo(i)%>, <%=lisCo(i)%>, <%=LisVo(i)%>])
<% Next%>

有什么想法吗?

最佳答案

我以前只这样做过一次,并且尝试了很多不同的选项,试图找到强大且可靠的东西。

最后,我不得不分解并使用 VBA 中的循环来解构该对象,调用 JavasScript 中的函数来重建它。

请原谅这个语法,我已经很久没有使用 VBA 了——它肯定是错误的

for i = 1 to numop
jsSetLisOp (i, LisOp(i))
jsSetLisCo (i, LisCo(i))
Next

Javascript

// Set up our magic function
var wrapper = (function() {
var arr = [];

function jsSetLisOp(idx, val) {
var o = arr[i] || {};
o.LisOp = val;
}

function jsSetLisCo(idx, val) {
var o = arr[i] || {};
o.LisCo = val;
}

return {
jsSetLisOp: jsSetLisOp,
jsSetLisCo: jsSetLisCo
arr = arr;
};

}());


// Move this to a global level so we can share them with VBA
var jsSetLisOp = wrapper.jsSetLisOp;
var jsSetLisCo = wrapper.jsSetLisCo;

var jsobject = wrapper.arr;

关于javascript - 数组 VBScript 到 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24129083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com