Mirth遍历GlobalMap

时间:2012-11-13 09:41:36

标签: mirth

在我的欢乐实现(Mirth Connect Server 2.2.1)中,我有一个GlobalMap,其中包含来自外部属性文件的键和属性。如何从Globalmap获取密钥集并迭代它以获取值?

2 个答案:

答案 0 :(得分:2)

您可以像这样迭代全局地图:

for each (key in globalMap.getVariables().keySet().toArray())
    logger.info(key+': '+$g('key'));

答案 1 :(得分:1)

我不确定你是如何初始化你的键/值集的,但这是我所做的基本概述。

在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;
}