0

我正在使用jsgantt库在我的网页上创建甘特图。问题如下。

变体 1 不工作,而变体 2 工作。显示“Start”警报,而函数内部不显示“Fin”警报createChartControl。所以,我无法弄清楚为什么变体 1 不工作(即空白 DIV 容器)并且 Firebug 不显示任何错误消息。非常感谢任何帮助。

变体 1:

    <script>
    function createChartControl(htmlDiv)
    {

alert("Start");

          var g = new JSGantt.GanttChart('g',document.getElementById(htmlDiv), 'hour');

          g.setShowRes(1); // Show/Hide Responsible (0/1)
          g.setShowDur(1); // Show/Hide Duration (0/1)
          g.setShowComp(1); // Show/Hide % Complete(0/1)
          g.setCaptionType('Resource');  // Set to Show Caption (None,Caption,Resource,Duration,Complete)
          g.setFormatArr("hours","minutes")

          if( g ) {

            // Parameters             (pID, pName,                  pStart,      pEnd,        pColor,   pLink,          pMile, pRes,  pComp, pGroup, pParent, pOpen)

            // You can also use the XML file parser JSGantt.parseXML('project.xml',g)

            g.AddTaskItem(new JSGantt.TaskItem(1,   'Add minutes/hours',            '',                 '',                 'ff0000', 'http://help.com',        0, 'Ilan',     0, 1, 0, 1));
            g.AddTaskItem(new JSGantt.TaskItem(11,  'Add support for half days',    '5/14/2009 14:00',  '5/14/2009 15:30',  'ff00ff', 'http://www.jsgantt.com', 0, 'Ilan',  100, 0, 1, 1));
            g.AddTaskItem(new JSGantt.TaskItem(12,  'Add minute view',              '5/14/2009 16:00',  '5/14/2009 17:00',  '00ff00', '',                       0, 'Ilan',   40, 0, 1, 1));
            g.AddTaskItem(new JSGantt.TaskItem(13,  'Add hours view',               '5/14/2009 16:00',  '5/14/2009 17:00',  '00ffff', 'http://www.yahoo.com',   0, 'Ilan', 60, 0, 1, 1));
            g.AddTaskItem(new JSGantt.TaskItem(14,  'Add support for format options',               '5/14/2009 18:00',  '5/14/2009 19:00',  '00ffff', 'http://www.yahoo.com',   0, 'Shlomy', 60, 0, 14, 1));


            g.Draw();   
            g.DrawDependencies();

alert("Fin");

          }
          else
          {
            alert("not defined");
          }
    }
    </script>

    <script>
    $(document).ready(function() {
                               createChartControl('schedule');

    });
    </script>

    <div style="position:relative" class="gantt" id="schedule"></div>

变体 2:

<div style="position:relative" class="gantt" id="schedule"></div>
<script>
      var g = new JSGantt.GanttChart('g',document.getElementById('schedule'), 'hour');

      g.setShowRes(1); // Show/Hide Responsible (0/1)
      g.setShowDur(1); // Show/Hide Duration (0/1)
      g.setShowComp(1); // Show/Hide % Complete(0/1)
      g.setCaptionType('Resource');  // Set to Show Caption (None,Caption,Resource,Duration,Complete)
      g.setFormatArr("hours","minutes")

      if( g ) {

        // Parameters             (pID, pName,                  pStart,      pEnd,        pColor,   pLink,          pMile, pRes,  pComp, pGroup, pParent, pOpen)

        // You can also use the XML file parser JSGantt.parseXML('project.xml',g)

        g.AddTaskItem(new JSGantt.TaskItem(1,   'Add minutes/hours',            '',                 '',                 'ff0000', 'http://help.com',        0, 'Ilan',     0, 1, 0, 1));
        g.AddTaskItem(new JSGantt.TaskItem(11,  'Add support for half days',    '5/14/2009 14:00',  '5/14/2009 15:30',  'ff00ff', 'http://www.jsgantt.com', 0, 'Ilan',  100, 0, 1, 1));
        g.AddTaskItem(new JSGantt.TaskItem(12,  'Add minute view',              '5/14/2009 16:00',  '5/14/2009 17:00',  '00ff00', '',                       0, 'Ilan',   40, 0, 1, 1));
        g.AddTaskItem(new JSGantt.TaskItem(13,  'Add hours view',               '5/14/2009 16:00',  '5/14/2009 17:00',  '00ffff', 'http://www.yahoo.com',   0, 'Ilan', 60, 0, 1, 1));
        g.AddTaskItem(new JSGantt.TaskItem(14,  'Add support for format options',               '5/14/2009 18:00',  '5/14/2009 19:00',  '00ffff', 'http://www.yahoo.com',   0, 'Shlomy', 60, 0, 14, 1));


        g.Draw();   
        g.DrawDependencies();

      }

      else

      {

        alert("not defined");

      }
</script>

更新 1:当我使用dhtmlxGantt库在函数 createChartControl 中创建图表时,我应该说 Variant 1 正在工作。

更新 2:我在变体 1 中更新了我的示例代码。它仍然无法正常工作 - 即显示警报“开始”,而警报“鳍”没有显示。

4

2 回答 2

1

你确定,你从 updateList 得到的响应是 JSON 对象吗?

echo json_encode(array('a'=>'b'));
die();

如果您不响应 JSON 对象,请使用 $.get() 方法。

PS:请不要使用 'updateList.php?query='+'DROP DATABASE()' 尝试一些 MVC 逻辑。

于 2012-08-11T18:28:07.590 回答
0

jsgantt 需要全局变量g才能工作。变成. var g_ 所以它看起来像这样window.g

变体 1:

<script>
    function createChartControl(htmlDiv)
    {
        alert("Start");

        window.g = new JSGantt.GanttChart('g',document.getElementById(htmlDiv), 'hour');

        g.setShowRes(1); // Show/Hide Responsible (0/1)
        g.setShowDur(1); // Show/Hide Duration (0/1)
        g.setShowComp(1); // Show/Hide % Complete(0/1)
        g.setCaptionType('Resource');  // Set to Show Caption (None,Caption,Resource,Duration,Complete)
        g.setFormatArr("hours","minutes")

        if(g) {
            // Parameters (pID, pName, pStart, pEnd, pColor, pLink, pMile, pRes, pComp, pGroup, pParent, pOpen)
            // You can also use the XML file parser JSGantt.parseXML('project.xml',g)

            g.AddTaskItem(new JSGantt.TaskItem(1, 'Add minutes/hours', '', '', 'ff0000', 'http://help.com', 0, 'Ilan', 0, 1, 0, 1));
            g.AddTaskItem(new JSGantt.TaskItem(11, 'Add support for half days', '5/14/2009 14:00', '5/14/2009 15:30', 'ff00ff', 'http://www.jsgantt.com', 0, 'Ilan', 100, 0, 1, 1));
            g.AddTaskItem(new JSGantt.TaskItem(12, 'Add minute view', '5/14/2009 16:00', '5/14/2009 17:00', '00ff00', '', 0, 'Ilan',  40, 0, 1, 1));
            g.AddTaskItem(new JSGantt.TaskItem(13, 'Add hours view', '5/14/2009 16:00', '5/14/2009 17:00', '00ffff', 'http://www.yahoo.com',  0, 'Ilan', 60, 0, 1, 1));
            g.AddTaskItem(new JSGantt.TaskItem(14, 'Add support for format options', '5/14/2009 18:00', '5/14/2009 19:00', '00ffff', 'http://www.yahoo.com',  0, 'Shlomy', 60, 0, 14, 1));

            g.Draw();
            g.DrawDependencies();

            alert("Fin");
        }
        else {
            alert("not defined");
        }
    }
</script>

<script>
    $(document).ready(function() {
        createChartControl('schedule');
    });
</script>
<div style="position:relative" class="gantt" id="schedule"></div>
于 2013-02-08T10:30:57.383 回答