如何在 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/