我为 JIRA 实例编写了一些 Javascript,在创建问题时自动填充字段。如果我在新窗口中打开“创建问题”屏幕,它会按预期工作。 但是,当对话框中出现“创建问题”时,我的脚本不会运行。 当“创建问题”对话框屏幕在窗口中打开时,如何使我的脚本运行? 下面是我的代码:
/*
* Automatically fills the summary field of an issue and hides the field at issue creation.
*/
jQuery(document).ready(function($) {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
autoFillSummary();
});
autoFillSummary();
// Automatically fill the summary field with a default value.
function autoFillSummary(){
var issueType = $('#issue-create-issue-type').text();
var reporter = $('#reporter').val();
var d = new Date();
d = d.toDateString();
var summaryVal = reporter + " - " + "[ " + d + " ]";
if(issueType === "Job"){
$('#summary').val(summaryVal);
$('#summary').closest('div.field-group').hide();
$('#reporter').closest('div.field-group').hide();
}
}
});
对话的 ID 是 create-issue-dialog 预先感谢您能为我提供的任何帮助。
最佳答案
我会这样做:
jQuery(document).ready(function($) {
$('#create-issue-dialog').dialog({
autoOpen: false,
open: function(event, ui) {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e, context) {
autoFillSummary();
});
}
});
// Automatically fill the summary field with a default value.
function autoFillSummary() {
var issueType = $('#issue-create-issue-type').text();
var reporter = $('#reporter').val();
var d = new Date();
d = d.toDateString();
var summaryVal = reporter + " - " + "[ " + d + " ]";
if (issueType === "Job") {
$('#summary').val(summaryVal);
$('#summary').closest('div.field-group').hide();
$('#reporter').closest('div.field-group').hide();
}
}
});
我从来没有用过 JIRA。
关于javascript - JQuery 在对话框加载时运行 Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29649823/