【发布时间】:2012-11-13 09:41:35
【问题描述】:
在我的 mirth 实现(Mirth Connect Server 2.2.1)中,我有一个 GlobalMap,其中包含来自外部属性文件的键和属性。如何从 Globalmap 中获取键集并对其进行迭代以获取值?
【问题讨论】:
标签: mirth
在我的 mirth 实现(Mirth Connect Server 2.2.1)中,我有一个 GlobalMap,其中包含来自外部属性文件的键和属性。如何从 Globalmap 中获取键集并对其进行迭代以获取值?
【问题讨论】:
标签: mirth
您可以像这样遍历全局地图:
for each (key in globalMap.getVariables().keySet().toArray())
logger.info(key+': '+$g('key'));
【讨论】:
我不确定你是如何初始化你的键/值集的,但这里是我所做的基本概要。
在 GlobalMap 中粘贴键/值集:
//I will assume that you have your own routine for initializing the
//kv set from your property file
var kvPairs = {'key1':'value1',
'key2':'value2',
'key3':'value3'};
globalMap.put('keyValuePairs',kvPairs);
从 GlobalMap 中提取集合:
// Method 1
// Grab directly from GlobalMap object.
var kvPairs = globalMap.get('keyValuePairs');
// Method 2
// Use the Mirth shorthand to search all map objects until the
// desired variable is located.
var kvPairs = $('keyValuePairs');
遍历集合:
// Method 1
// If you need to access both the keys and the associated values, then
// use a for in loop
for (var key in kvPairs)
{
var value = kvPairs[key];
// you now have key and value, and can use them as you see fit
}
// Method 2
// If you only need the values, and don't need the keys, then you can use
// the more familiar for each in loop
for each (var value in kvPairs)
{
// you now have value, and can use it as you see fit;
}
【讨论】: