通过 wicket 动态编写脚本 src [英] Writing script src dynamically via wicket

查看:32
本文介绍了通过 wicket 动态编写脚本 src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的页面将 javascript 动态加载到我的正文:

I want my page to load javascript dynamically to my body:

<script type= "text/javascript" src="this path should be decided from wicket dynamically"/>

我使用的是 wicket 1.4 版,因此 JavaScriptResourceReference 在我的版本中不存在(我检查它不是 ' )

I am using wicket version 1.4 therefore JavaScriptResourceReference does not exist in my version (for my inspection it wasn't ' )

我该如何解决这个问题?提前致谢:)

how can I solve this ? thanks in advance :).

推荐答案

我将我的评论指定为答案.

I specify my comment into an answer.

您可以使用以下代码片段:

You can use this code snippet:

WebMarkupContainer scriptContainer = new WebMarkupContainer("scriptContainer ");
scriptContainer .add(new AttributeAppender("type", Model.of("text/javascript")));
scriptContainer .add(
    new AttributeAppender("src", urlFor(
        new JavaScriptResourceReference(
            YourClass.class, "JavaScriptFile.js"), null).toString()));
add(scriptContainer );

和相应的html:

<script wicket:id="scriptContainer "></script>

只需更改字符串 JavaScriptFile.js 即可加载任何其他 Javascript 文件.

Just change the string JavaScriptFile.js to load any other Javascript file.

这篇关于通过 wicket 动态编写脚本 src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆