【问题标题】:How to add new JS libraries in Alfresco Share Controls?如何在 Alfresco Share Controls 中添加新的 JS 库?
【发布时间】:2019-07-25 21:47:10
【问题描述】:

我正在尝试使用select2 库开发新的自定义控件模板。为此,我必须包含 CSS 和 JS 文件。 我怎样才能做到这一点?

我知道我可以在 tomcat 文件夹中手动添加这些文件,但我在 Docker 上,所以我无权访问它。

显然我尝试将它们包含在 .ftl 文件中的 <head> 标记中,但它不起作用。

这是我的 customcontrol.ftl

<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.8/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.8/js/select2.min.js"></script>

<select class="courntyselect">
  <option></option>
  <option value="1">USA</option>
  <option value="2">France</option>
  <option value="3">Tunisia</option> 
  <option value="4">Canada</option> 
</select>

<script type="text/javascript">
$(".courntyselect").select2({
  width: "250",
  placeholder: "Select your country",
}).on("change",function(e){
  alert('Selected value : ' + e.target.value);
});
</script>

【问题讨论】:

    标签: alfresco freemarker alfresco-share alfresco-enterprise


    【解决方案1】:

    您需要在 share-config-custom.xml 中添加这些文件作为依赖项。

    <config>
            <forms>
                <dependencies>
                    <js src="/js/datatable-datasource-min.js" />
                </dependencies>
            </forms>
        </config>
    

    将 js 文件放在共享文件夹的 src\main\amp\web\js 中。

    【讨论】:

    • 好的,但是我怎样才能把这个文件上传到 /js 文件夹呢?我应该将它放在 Share AMP 项目中的什么位置?我尝试了 src/main/resources/js/ 但它不起作用(文件未上传)
    • 好的,我可以将它们放在服务器上(修改 Dockerfile ),但我在 localhost:8180/share/res/js/… 文件的浏览器控制台中收到“TypeError: element is undefined”错误(我只能空白页)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多