如何更新数组范围变量中的值? [英] how to update a value in array scoped variable?
问题描述
我有一个存储档案的作用域变量:
viewScope.MY_SCOPE = new Array();viewScope.MY_SCOPE.push(["id0", 0, true]);viewScope.MY_SCOPE.push(["id1", 1, false]);viewScope.MY_SCOPE.push(["id2", 3, true]);
现在我想更新其中一项.
viewScope.MY_SCOPE[1][2] = "true";
这失败并出现错误:
<块引用>执行 JavaScript 动作表达式时出错 put(int index,FBSValue value)
在 JavaWrapperObject
中不受支持.
如何更新数组中的特定项目?
当将 SSJS 数组对象添加到作用域时,它被转换为 java.util.Vector.因此,如果你想设置这个值,你应该使用
viewScope.MY_SCOPE[1].set(2,"true");
而不是 viewScope.MY_SCOPE[1][2] = "true";
.
我认为问题在于使用 ...[2]= "true"
尝试执行给定对象的 put
方法.虽然 put
在 Maps 中可用,如 HashMaps 或范围映射,但 Vectors 使用 set
而不是 put
来更改值.因此,您会收到不支持操作表达式 put(...)"错误.与此相反,使用 viewScope.MY_SCOPE[1][2]
获取变量没有问题,因为 get
方法在 HashMaps 和 Vectors 中都可用.>
I have a scoped variable that stores an archive:
viewScope.MY_SCOPE = new Array();
viewScope.MY_SCOPE.push(["id0", 0, true]);
viewScope.MY_SCOPE.push(["id1", 1, false]);
viewScope.MY_SCOPE.push(["id2", 3, true]);
now I want to update one of item.
viewScope.MY_SCOPE[1][2] = "true";
and this fails with the error:
Error while executing JavaScript action expression
put(int index,FBSValue value)
not supported inJavaWrapperObject
.
How do I update a specific item in the array?
When adding the SSJS array object to the scope, it is converted to a java.util.Vector. Hence, if you want to set the value, you should use
viewScope.MY_SCOPE[1].set(2,"true");
instead of viewScope.MY_SCOPE[1][2] = "true";
.
I think the problem is that using ...[2] = "true"
tries to execute the put
method of the given object. While put
is available in Maps like HashMaps or the scope maps, Vectors use set
instead of put
to change values. For that reason, you get the "action expression put(...) not supported" error. In contrast to this, it's no problem to get the variable with viewScope.MY_SCOPE[1][2]
because the get
method is availiable in both HashMaps and Vectors.
这篇关于如何更新数组范围变量中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!