2
在我的歡樂實現(Mirth連接服務器2.2.1)我有一個GlobalMap包含鍵和屬性來自外部屬性文件。如何從Globalmap獲取密鑰集並迭代它以獲取值?歡樂遍歷GlobalMap
在我的歡樂實現(Mirth連接服務器2.2.1)我有一個GlobalMap包含鍵和屬性來自外部屬性文件。如何從Globalmap獲取密鑰集並迭代它以獲取值?歡樂遍歷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);
要從辦事處一覽中提取所述一組:
// 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;
}
:
// 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');
要通過集迭代你可以遍歷全局地圖,如下所示:
for each (key in globalMap.getVariables().keySet().toArray())
logger.info(key+': '+$g('key'));