2012-07-09 379 views
0

我的應用程序有一個指示器列表,每個指示器都有其幫助按鈕。點擊每個按鈕,分別爲每個按鈕提供一個帶有定義的ToolTipDialog。我編寫代碼的方式(如下所示),當用戶單擊第一個單擊按鈕後單擊列表中的另一個幫助按鈕時,內容不會刷新。我一直無法弄清楚如何動態改變「內容」。任何幫助將不勝感激:動態更改ToolTipDialog內容

HTML:

<div dojoType="dijit.layout.ContentPane" id="group1" title="Population projection" selected="true"> 
<table id="popIndTable"> 
<tr id="someID"> 
<td><input data-dojo-type="dijit.form.RadioButton" class="checkInd" id="checkCBR" name="checkInd" /></td> 
<td id="indCBR">Crude Birth Rate</td> 
<td id="infoCBR"><img id="imgCBR" src="Images/help_icon2.png" width="16px" onClick="showToolTipDialog(this,this.id);" /></td> 
</tr> 
<tr> 
<td><input data-dojo-type="dijit.form.RadioButton" class="checkInd" id="checkTest1" name="checkInd" /></td> 
<td id="indTest1">Test 1</td> 
<td id="infoTest1"><img id="imgTest1" src="Images/help_icon2.png" width="16px" onClick="showToolTipDialog(this,this.id);" /></td> 
</tr> 
<tr> 
<td><input data-dojo-type="dijit.form.RadioButton" class="checkInd" id="checkTest2" name="checkInd" /></td> 
<td id="indTest2">Test 2</td> 
<td id="infoTest2"><img id="imgTest2" src="Images/help_icon2.png" width="16px" onClick="showToolTipDialog(this,this.id);" /></td> 
</tr> 
</table> 
</div> 

的JavaScript:

function showToolTipDialog(node,infoId){ 
var infoText; 
var infoElem = dojo.byId(infoId).parentNode.id; 
if (infoElem == "infoCBR"){ 
infoText = "This is the text container for CBR"; 
} 
else if (infoElem == "infoTest1"){ 
infoText = "This is the text container for Test1"; 
} 
if (!tooltipDialog) { 
tooltipDialog = new dijit.TooltipDialog({ 
content: infoText, 
style: "width:200px;height:auto;", 
autofocus: !dojo.isIE, // NOTE: turning focus ON in IE causes errors when reopening the dialog 
refocus: !dojo.isIE 
}); 
dijit.popup.open({ popup: tooltipDialog, around: node}); 
tooltipDialog.opened_ = true; 
} 
else { 
if (tooltipDialog.opened_) { 
dijit.popup.close(tooltipDialog); 
tooltipDialog.opened_ = false; 
} 
else { 
dijit.popup.open({popup: tooltipDialog, around: node}); 
tooltipDialog.opened_ = true; 
} 
} 
} 

回答

0

它看起來像你從來沒有重置tooltipDialog的內容。您創建一次,但一旦創建它(new dijit.TooltipDialog({...}))它仍然是靜態的。

我不知道Dojo API。但是,你能直接設置內容值嗎?也許之後你的第一else

tooltipDialog.content = infoText; 

這只是一個猜測,但如果Dojo的API是很簡單的,可能做的伎倆。

如果不是,您可能需要刪除您的if (!tooltipDialog) {支票。

+0

謝謝斯科特,我確實通過刪除「如果......」來嘗試代碼,但它並沒有幫助我解決問題。 – samirg 2012-07-09 18:18:35

+0

您是否嘗試了我的主要建議?無論如何,這樣會更好。 – 2012-07-09 18:34:22

+0

我也嘗試過,但它不適合我。我正在重新思考代碼的邏輯,並可能對其進行一些更改。但如果有其他選擇,我會很樂意嘗試其他選擇。 – samirg 2012-07-09 18:42:28

1

我相信以編程方式更改dojo小部件值的首選方法是使用.set()方法。即:

this.myTooltipDialog.set("content", newContent); 

不是:

this.myTooltip.content = newContent; 
-1

如果你的內容是不是太複雜,我建議你創建一個新的TooltipDialog每一個電話,當模糊清除它,就像

var dlgDiv = dojo.create("div"); 
var dlg = new dijit.TooltipDialog({ 
    content: dlgDiv, 
    onBlur: function() { 
     popup.close(this); 
     this.destroyRecursive(); 
    } 
}); 

// you can create any content within dlgDiv at here dynamicly 

dojo.popup.open({ 
    around: yourArondNode , 
    orient: ["below", "before", "after", "above"], 
    popup: dlg 
}); 
dlg.focus(); 
+0

昂貴的答案和不必要的 – ed4becky 2015-11-25 13:16:50