【发布时间】:2013-08-13 11:17:20
【问题描述】:
我在 C# 中创建了一个 Com 组件并尝试在 Javascript 中访问。
我的 C# 方法是
Class myComComponent
{
private int[] nAllData;
public int[] GetArray(int index)
{
//Some Logic here that will return integer type of array{1,12,15,48,1452,45}
return nAllData;
}
}
从 javascript 调用它,但它给了我一个类型不匹配的错误。
Javascript 代码
function MyComComponent_onload() {
try {
var nAllData = new Array();
for (var i = 0; i<= 5; i++)
{
nAllData.push(myComComponent.GetArray(i));
}
}
catch (err)
{
alert(err.message);
}
}
<html>
<head>
<object id="myComComponent" name="myComComponent" classid="clsid:4794D615-BE51-4A1E-B1BA-453F6E9337C4">
</head>
<body onload="MyComComponent_onload();">
//// Html Code goes here
</body>
<html>
【问题讨论】:
-
你的 c# 函数返回一个整数数组,所以你需要在你的 javascript 中使用一个二维数组来存储这些数组......我是对的吗?
-
@Giwrgos Tsopanoglou 我该怎么做。我不知道如何转换它。你能简单告诉我吗
-
我从未结合过 c# 和 javascript,而且我也不是专家。也许您可以尝试在 for 循环中添加“nAllData[i] = new Array()”。
标签: c# javascript html c#-4.0 com