javascript - 在jira插件中使用静态资源(例如JQuery)

标签 javascript jquery plugins resources jira

如何在 Atlassian Jira 4.4 插件中包含 Web 资源?

atlassian-plugin.xml:

 <web-resource key="statistics-resources" name="statistics">
    <resource type="download" name="statistics.js" location="js/statistics/statistics.js"/>
    <dependency>jira.webresources:jira-global</dependency>
    <context>com.cs.jira.plugins.statistics-resources</context>
</web-resource>

统计.js:

$("#projects").change(function() {
$(location).attr('href', "/jira/secure/StatisticsModuleAction!project.jspa?project=" + $(this).find("option:selected").text());});

在 Velocity 模板中包含资源:

$webResourceManager.requireResourcesForContext("com.cs.jira.plugins.statistics-resources")

当我尝试从 stats.js 调用 javascript 函数时,出现此错误:

Uncaught TypeError: Property '$' of object [object Window] is not a function

然后我尝试包含外部 jQuery 库:

<web-resource key="statistics-resources" name="statistics">
    <resource type="download" name="jquery-1.8.2.js" location="js/lib/jquery-1.8.2.js"/>
    <resource type="download" name="statistics.js" location="js/statistics/statistics.js"/>
    <dependency>jira.webresources:jira-global</dependency>
    <context>com.cs.jira.plugins.statistics-resources</context>
</web-resource>

我在batch.js中遇到另一个错误:

Uncaught TypeError: Object [object Object] has no method 'handleAccessKeys'

如何正确包含我的资源?

最佳答案

据我所知,您已正确包含统计资源。您的问题是 Jira 通过与 jquery 标准不同的引用提供对 jquery 的访问。如果您在 JavaScript 代码中将 $ 替换为 AJS.$,它应该可以解决您的问题。

关于javascript - 在jira插件中使用静态资源(例如JQuery),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12687403/

相关文章:

javascript - 如何在 Node.js 中进行 64 位整数运算?

javascript - jQuery 选择-选择防止隐藏选择

javascript - Angular 4 Swiper集成(js初始化)

jquery - 在同一页面中创建 2 个不同的选项卡

javascript - 在没有 div 的情况下将 Javascript 字符串插入到 html 中的最简单方法?

java - 开发 eclipse 插件来解析 java 程序的程序

javascript - AngularJS 指令模板中的 ng-repeat

javascript - jQuery.html() 结果,浏览器不解释为 HTML

iOS Cordova : Does Cordova create multiple instances of an objective-C plugin when called more than once?

database - 我需要一个客户端浏览器数据库。我有什么选择