2017-07-04 33 views
1

我有一個加載表格和圖表dhtmlxgantt一個HTML頁面。以下作品中的JavaScript功能,但現在我想從一個不同的HTML加載的甘特圖,並通過iframe中顯示。用的onClick功能獲取ID和填充它在不同的HTML

我怎樣才能從main_page.html表得到content_id並填充它​​甘特圖

每個人都可以幫助非常感謝

main_page.html

<table id="project-content-datatable"> 
    <tbody> 
     <tr> 
      <td class="project_content_id">1</td> 
      <td class="project_content_id">2</td> 
      <td class="project_content_id">3</td>  
     </tr> 
    </tbody> 
</table> 

<div class="col-md-12" style="padding: 3px; margin: 0px;"> 
    <iframe src="/dashboard/projects/scheduler.html" height="330"; width="99%" style="border:2px solid blue; border-radius: 5px;"></iframe> 
</div> 

scheduler.html

<div id="my_scheduler" style='width:1567px; height:325px;'></div> 

JavaScript的

$('#project-content-datatable').on('click', 'tr', function() { 
    var content_id =$(this).closest('tr').children('td.project_content_id').text(); 
    initializeGantt(content_id) 
    }); 

    gantt.config.xml_date = "%Y-%m-%d"; 
    function initializeGantt(content_id) { 
     scheduler = gantt.init("my_scheduler", new Date('2017, 01, 01'), new Date('2017, 12, 31')); 
     $.get("/dashboard/ganttchart_list/"+content_id+"/?format=json", function(result) { gantt.parse(prepareData(result)); }); 
    } 

    initializeGantt(); 

回答

0

一個簡單的方法做,這是調用動態創建您傳遞給的iframe的網址:

<div class="col-md-12" style="padding: 3px; margin: 0px;"> 
    <iframe id="iframe" height="330"; width="99%" style="border:2px solid blue; border-radius: 5px;"></iframe> 
</div> 

,並在你的腳本:

var url = "/dashboard/projects/scheduler.html?content_id=" + content_id; 
document.getElementById('iframe').src = url; 

現在內iframe的可以從window.hash獲取內容的ID。提取的ID可以,在這種特殊情況下,很容易地與一個子完成,但對於一個更完整的方法,你可以使用這裏描述的從URL中提取查詢參數的函數:How can I get query string values in JavaScript?

相關問題