2012-01-21 34 views
1

我有以下功能,我嘗試將指定的url加載到新的或現有的選項卡(contentPane)中,但我大多數情況下都能工作,但是當指定現有選項卡時原始網址仍然重新加載,而不是添加新的HTML,我怎樣才能完成現有標籤傳遞的部分,而不必在創建新標籤時刪除屬性refreshOnShow?使用Dojo打開某個選項卡中的URL

openTab = function(url,title, id){ 
    var tab = dijit.byId(id); 
    var centerPane = dijit.byId('centerPane'); 

    if (tab){ 
     //if target container exists then let's load the url and add it to the container 
     centerPane.selectChild(tab); 
     $.get(url, function(data) { 
      $('#'+id).html(data); 

     }); 
     centerPane.selectChild(tab); 


    } else { 

     var newTab = new dijit.layout.ContentPane(
       { 
       'title': title, 
       href:url, 
       closable:true, 
       selected:true, 
       parseOnLoad:true, 
       preventCache:true, 
       refreshOnShow:true 
      }, id); 
     centerPane.addChild(newTab); 
     centerPane.selectChild(newTab); 
    } 
}; 

回答

1

這是我更新的功能看起來如何,它爲我工作:

openTab = function(url,title, id){ 
     var tab = dijit.byId(id); 
     var centerPane = dijit.byId('centerPane'); 
     if (tab){ 
      //if target container exists then let's load the url and add it to the container 
      tab.href = url; 
      tab.set('title',title); 
      centerPane.selectChild(tab); 
     } else {   
      var newTab = new dijit.layout.ContentPane(
       { 
        'title': title, 
        href:url, 
        closable:true, 
        selected:true, 
        parseOnLoad:true, 
        preventCache:true, 
        refreshOnShow:true 
       }, id); 
      centerPane.addChild(newTab); 
      centerPane.selectChild(newTab); 
     } 


    }; 
1

所以,你在做什麼基本上是說,當這個標籤被重新打開,讓我追加我的內容,並且道場是說,「我剛打開此選項卡,並refreshOnShow是真實的,所以讓我再次從服務器獲取我的內容'。

我認爲最簡潔的方式來解決這個問題,就是按照你說的做,並將refreshOnShow設置爲false。爲什麼你將它設置爲true,該選項卡是否需要從服務器始終刷新內容?

如果你想要的是這樣的(對於現有的標籤):

  1. 用戶點擊
  2. 道場去,並刷新現有的標籤內容
  3. 你手動(基於jQuery)處理器處理的,並得到其他一些內容 並追加到(或以其他方式使用它)的內容道場 自動刷新

然後你SH烏爾德能夠做這樣的事情:

newTab.connect(newTab, 'onLoad', function(){ 
// do my stuff after the dojo content has loaded 
}) 

這只是增加了一個事件處理程序到contentPane您標籤觸發該標籤已經到服務器的內容之後。

+0

看來,如果我剛纔設置的** **的href屬性類似這樣的** tab.href =網址; **做訣竅,但是我不能通過同樣的方式重新設置現有標籤的標題:** tab.title = title; ** – MikeGA

+0

嘗試使用'tab.set('title','我難以置信的標題') ' – mtyson

+0

太棒了!這樣可行! – MikeGA

相關問題