Javascript 正在将vbs转换为js:for each。。。在里面
我正在将一些旧的VBScript转换为Javascript,其中有两行我不知道如何正确转换。以下是原始VBS:Javascript 正在将vbs转换为js:for each。。。在里面,javascript,asp.net,vbscript,Javascript,Asp.net,Vbscript,我正在将一些旧的VBScript转换为Javascript,其中有两行我不知道如何正确转换。以下是原始VBS: function getCount() on error resume next dim allitems, strItemID, icnt icnt = 0 set allitems = dsoITEMS.selectNodes("//item") for each node in allitems
function getCount()
on error resume next
dim allitems, strItemID, icnt
icnt = 0
set allitems = dsoITEMS.selectNodes("//item")
for each node in allitems
strItemID = node.selectsinglenode("item_id").firstchild.nodevalue
if err then
exit for
end if
if strItemID <> "" then
icnt = icnt + 1
end if
next
set nodes = nothing
getCount = icnt
end function
我不知道如何转换的行是“出错后继续下一步”和“allitems中的每个节点”下面是VBS代码到JavaScript的转换: 使用try{}catch{}捕获错误。 在迭代项集合时,可以使用如下所示的for循环进行迭代,并使用index属性访问项。 在返回函数中的值时,还需要使用“return”关键字
function getCount() {
var allitems, strItemID, icnt;
icnt = 0;
try {
allitems = dsoITEMS.selectNodes("//item");
for(var i = 0; i<= allitems.length; i++){
var node = allitems[i];
strItemID = node.selectsinglenode("item_id").firstchild.nodevalue;
if (strItemID !== ""){
icnt = icnt + 1;
}
}
}
catch (ex){
//Do something with the errors (if you want)
}
return icnt;
}
函数getCount(){
变种allitems、strItemID、icnt;
icnt=0;
试一试{
allitems=dsoITEMS.selectNodes(//项);
对于(var i=0;i,以下是VBS代码到JavaScript的转换:
使用try{}catch{}捕获错误。
在迭代项集合时,可以使用如下所示的for循环进行迭代,并使用index属性访问项。
在返回函数中的值时,还需要使用“return”关键字
function getCount() {
var allitems, strItemID, icnt;
icnt = 0;
try {
allitems = dsoITEMS.selectNodes("//item");
for(var i = 0; i<= allitems.length; i++){
var node = allitems[i];
strItemID = node.selectsinglenode("item_id").firstchild.nodevalue;
if (strItemID !== ""){
icnt = icnt + 1;
}
}
}
catch (ex){
//Do something with the errors (if you want)
}
return icnt;
}
函数getCount(){
变种allitems、strItemID、icnt;
icnt=0;
试一试{
allitems=dsoITEMS.selectNodes(//项);
对于(var i=0;itry{janky code here}catch(y){console.error(y);}
alitems行中的每个节点该怎么办?try{janky code here}catch(y){console.error(y);}
alitems行中的每个节点该怎么办?