javascript - JQuery 在对话框加载时运行 Javascript

标签 javascript jquery dialog jira

我为 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/

相关文章:

c# - 在 IIS 中发布后未呈现 BundleConfig

javascript - 如何将对话框位置置于页面中央?

javascript - 如何在 $.ajax() 的成功函数中加载 Javascript 文件?

javascript - 将 Javascript 变量插入 JSON 对象

jQuery 删除表格列

javascript - jQuery.post 使用当前位置的修改后的 url,而不是提供的 url

c++ - 结构值不留,值改为-858993460

android两次调用相同的对话框

java - AJAX 请求使用哪种 HTTP GET/POST 方法?

javascript - 如何在angularjs中查找最后一个字母的字符串?