如何实现间接

How to implement indirection

一个人如何间接指代任何事物?在我的例子中,它是一个列名。语言文档的 "Field Access" 部分让我毫无头绪。

例如

let
    OriginalStrings = "some string with {tkn1} and/or {tkn2}"
    ,ParamTable = [tkn1 = "this", tkn2 = "that"]
    ,Result = List.Accumulate(Record.FieldNames(ParamTable),OriginalStrings
                             ,(txt,current) => Text.Replace(txt,"{"&current&"}",ParamTable[current]))
in
    Result

这导致:未找到记录的字段 'current'。我想要的是 'current' 的值作为标识符而不是文字。

上面的代码应该导致 "some string with this and/or that"

与我的 类似,Expression.Evaluate 可能会满足您的需求。

ParamTable[current]替换为

Expression.Evaluate("ParamTable["&current&"]", [ParamTable=ParamTable])

查看 this articleExpression.Evaluate() 和非全局环境 部分,以更清楚地了解环境参数。