2010-07-15 24 views
0

我正在使用JavaScript根據從下拉菜單中選擇的錯誤狀態,將特定的默認文本動態輸出到Bugzilla中的其他評論框。我嘗試過使用'bug.bug_status',但這隻會在頁面提交時發生變化。我找到了填充下拉菜單的變量'bug_status.name',但是當我嘗試使用這個變量時,它似乎沒有被識別。有沒有人有任何建議可能會導致問題?有沒有人試過這個?在Bugzilla中訪問bug_status.name的問題

以下代碼已放置在knob.html.tmpl文件的開頭。

[% PROCESS global/variables.none.tmpl %] 
[% # Output a specific default content in the comments box depending on bug status. %] 
<script type="text/javascript"> 
<!-- 
var messages = ['Message 0', 'Message 1', 'Message 2', 'Message 3', 'Message 4', 'Message 5', 'Message 6']; 
function changetext(selectObj){ 
    var textAreaElement = document.getElementsByName("comment")[0]; 
[% IF (bug_status.name == "ASSIGNED") %] 
    textAreaElement.value = messages[4]; 
[% ELSIF(bug_status.name == "RESOLVED") %] 
    textAreaElement.value = messages[5]; 
[% ELSE %] 
    var variable1 = 0; 
    variable1 = bug_status.name 
    textAreaElement.value = variable1; 
[% END %] 

回答

0

基於your other question,它似乎想要這個改變對客戶端的用戶正在選擇新的狀態。但是,您在此問題中編寫的代碼將在客戶端看到之前在服務器端更改。您的if/else樹需要使用JavaScript而不是模板工具包編寫。

所以,這樣的事情:

function changetext(selectObj){ 
    var textAreaElement = document.getElementsByName("comment")[0]; 
    var currentStatus = document.getElementById("bug_status").value; 

    if (currentStatus == "ASSIGNED") { 
    textAreaElement.value = messages[4]; 
    } else if (currentStatus == "RESOLVED") { 
    textAreaElement.value = messages[5]; 
    } else { 
    textAreaElement.value = currentStatus; 
    } 
} 
+0

那正是它,感謝您的幫助。 – user379222 2010-07-15 15:06:38