将两个向量展平为一张地图的好方法?
Nice way to flatten two vectors into 1 map?
有没有更好的方法可以将 Notes 文档中的两个多值字段展平到 SSJS 中的地图集合中?
到目前为止,我得出以下结论:
var vw:NotesView = database.getView("configuration");
if(null != vw){
var doc:NotesDocument = vw.getFirstDocument();
if (null != doc){
var itemname1:string = "userName";
var itemname2:string = "inboxFile";
if(doc.hasItem(itemname1) && doc.hasItem(itemname2)){
var itemvalues1:java.util.Vector = doc.getItemValue(itemname1);
var itemvalues2:java.util.Vector = doc.getItemValue(itemname2);
if(itemvalues1.size() == itemvalues2.size()){
var map = new java.util.HashMap();
var iterator1 = itemvalues1.iterator();
var iterator2 = itemvalues2.iterator();
}
while (iterator1.hasNext()) {
var itemvalue1 = iterator1.next();
var itemvalue2 = iterator2.next();
if ((typeof(itemvalue1)).endsWith("string")) {
map.put(itemvalue1.left(80), itemvalue2.left(80));
}
}
sessionScope.put("setupInbox",map)
}
}
}
如果支持 JavaScript forEach
构造,您可以使用此:
function mergeVector(keyVector, valueVector) {
var map = new java.util.HashMap();
keyVector.forEach(function(curKey, index) {
if (index < valueVector.size()) {
map.put(curKey, valueVector.get(index));
}
});
return map;
}
否则使用:
function mergeVector(keyVector, valueVector) {
var map = new java.util.HashMap();
for(var index = 0; index < keyVector.size(), index++) {
if (index < valueVector.size()) {
map.put(keyVector.get(index), valueVector.get(index));
}
};
return map;
}
希望对您有所帮助
有没有更好的方法可以将 Notes 文档中的两个多值字段展平到 SSJS 中的地图集合中?
到目前为止,我得出以下结论:
var vw:NotesView = database.getView("configuration");
if(null != vw){
var doc:NotesDocument = vw.getFirstDocument();
if (null != doc){
var itemname1:string = "userName";
var itemname2:string = "inboxFile";
if(doc.hasItem(itemname1) && doc.hasItem(itemname2)){
var itemvalues1:java.util.Vector = doc.getItemValue(itemname1);
var itemvalues2:java.util.Vector = doc.getItemValue(itemname2);
if(itemvalues1.size() == itemvalues2.size()){
var map = new java.util.HashMap();
var iterator1 = itemvalues1.iterator();
var iterator2 = itemvalues2.iterator();
}
while (iterator1.hasNext()) {
var itemvalue1 = iterator1.next();
var itemvalue2 = iterator2.next();
if ((typeof(itemvalue1)).endsWith("string")) {
map.put(itemvalue1.left(80), itemvalue2.left(80));
}
}
sessionScope.put("setupInbox",map)
}
}
}
如果支持 JavaScript forEach
构造,您可以使用此:
function mergeVector(keyVector, valueVector) {
var map = new java.util.HashMap();
keyVector.forEach(function(curKey, index) {
if (index < valueVector.size()) {
map.put(curKey, valueVector.get(index));
}
});
return map;
}
否则使用:
function mergeVector(keyVector, valueVector) {
var map = new java.util.HashMap();
for(var index = 0; index < keyVector.size(), index++) {
if (index < valueVector.size()) {
map.put(keyVector.get(index), valueVector.get(index));
}
};
return map;
}
希望对您有所帮助