Tapestry:访问相应javascript文件中的页面/组件属性

Tapestry : Access page/component property in corresponding javascript file

本文关键字:属性 组件 文件 访问 javascript Tapestry      更新时间:2023-09-28

假设我有一个名为testComp的组件,它具有字符串属性testProperty。对应testComp.java的是一个js文件testComp.js

如何在testComp.js中访问testProp?

我试着跟随,但它给出了一个错误。

console.log( ${testProp} );

我知道我可以在html文件中执行${testProp},但我需要在javascript文件中访问此属性。我已经在邮件列表中搜索过了,但到目前为止没有运气。知道怎么做吗?

试试这个:

testComp.java

@Inject
private JavaScriptSupport javaScriptSupport;
@AfterRender
private void after() throws Exception {
    JSONObject arguments = new JSONObject();
    arguments.put("testProperty", this.testProperty);
    javaScriptSupport.addInitializerCall("testComp", arguments);
}

testComp.js

Tapestry.Initializer.testComp = function (json) {
    new testComp(json);
};

function testComp(json){
    alert(json.testProperty);
}