我不明白如何使用extendedChoice 参数的'bindings' 字段,我检查了插件的源代码,发现它在groovyShell 的上下文中添加了变量,但我不明白如何访问这个上下文。
我尝试像这样设置绑定:
def bindings = new Binding()
bindings.setProperty("foo", "foo value")
return extendedChoice(
name: 'jsonParameters',
bindings: bindings.getVariables().toString(),
type: 'PT_JSON',
javascript: jsScript,
groovyScript: groovyScript)
然后在“groovyScript”中,我希望能够访问我的“foo”变量......
更新:我创建了一个简单的测试,“绑定”是全局的,我可以访问它!为什么不在我的带有插件的 groovyscript 中?
def bindings = new Binding()
bindings.setVariable("foo", "bar")
GroovyShell groovyShell = new GroovyShell();
Script compiledScript = groovyShell.parse("""
println "foo: " + binding.variables.get("foo")
""");
compiledScript.setBinding(bindings);
compiledScript.run();
// print "foo: bar"
插件版本:0.78