从PowerShell中的哈希表获取密钥值时修改值

时间:2015-04-27 04:49:43

标签: powershell hashtable

在PowerShell中,我有一个如此创建的结构(HashTable类型):

$Structure = @{
    "KeyOne" = "Value"
    "KeyTwo" = "{Change.This.That}"
    "KeyThree" = "{Change.This.Thing} With Stuff"
    "Change" = @{
        "This" = @{
            "That" = "Another Value"
            "Thing" = "Yogurt"
        }
    }
}

带有大括号的字符串是占位符/标记,用于实际值应该是什么,以字符串格式存储,作为对同一对象中某些其他值的点表示法的引用。

我编写了一个函数来获取该标记化值并检索实际值应该是什么,它完全正常。唯一的问题是每次有标记值时我都必须执行该功能。无论如何我可以简化这个,特别是不运行:

#I pass structure because I'd rather avoid assuming 
#the hashtable will always be called $Structure
Convert-Token -String $Structure.KeyTwo -Obj $Structure #Another Value

无论如何我只能通过拉括号表示法自动执行此操作吗?

#Like this?
$Value = $Structure["KeyThree"]
$Value #Yogurt With Stuff

可能?不可能?

1 个答案:

答案 0 :(得分:1)

你可以这样做:

 $( "#refreshTree" ).on( "click", function(event)
 {
    event.preventDefault();
    tree.jstree("refresh");  
 });