2

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

4

2 回答 2

2

您可以像这样遍历全局地图:

for each (key in globalMap.getVariables().keySet().toArray())
    logger.info(key+': '+$g('key'));
于 2013-01-22T19:45:26.580 回答
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;
}
于 2012-11-28T00:33:58.950 回答