2012-04-21 54 views
0

我有一個dojox.grid.DataGrid。在該正在與最後2列被填滿了,其根據在gridStruture使用formatter屬性從數據庫被檢索數據動態創建buttons顯示一組值的沿。現在我得到了我的網格很好。按鈕也很好。我現在需要做的是當我點擊該按鈕上的特定按鈕時,單擊事件,我將其重定向到一個具有特定值(A)的新URL,作爲該URL中的查詢字符串參數傳遞。我不希望我的頁面被刷新。就像點擊一個按鈕時,它會在其他某個JSP頁面上執行操作,並顯示消息alert("Action is being performed")。在那裏我有編碼爲我的數據網格執行操作按鈕單擊事件,按鈕被放置在dojox.grid.DataGrid內。

我的Java腳本代碼::

<script type="text/javascript"> 
function getInfoFromServer(){ 
     $.get("http://localhost:8080/2_8_2012/jsp/GetJson.jsp?random=" + new Date().getTime(), function (result) { 
     success:postToPage(result), 
     alert('Load was performed.'); 
      },"json"); 
    } 


    function postToPage(data){ 
    alert(data);  
    var storedata = { 
     identifier:"ActID", 
     items: data 
     }; 
    alert(storedata); 

    var store1 = new dojo.data.ItemFileWriteStore({data: storedata}) ; 
    var gridStructure =[[ 

          { field: "ActID", 
           name: "Activity ID", 

           classes:"firstName" 
          }, 
          { 
           field: "Assigned To", 
           name: "Assigned To", 

           classes: "firstName" 
          }, 
          { field: "Activity Type", 
           name: "Activity Type", 

           classes:"firstName" 
          }, 
          { 
           field: "Status", 
           name: "Status", 

           classes: "firstName" 
          }, 
          { 
           field: "Assigned Date", 
           name: "Assigned Date", 

           classes: "firstName" 
          }, 
          { 
           field: "Assigned Time", 
           name: "Assigned Time", 

           classes: "firstName" 
          }, 
          { 
           field: "Email", 
           name: "Send Mail", 
           formatter: sendmail, 
           classes: "firstName" 

          }, 
          { 
           field: "ActID", 
           name: "Delete", 
           formatter: deleteact, 
           classes: "firstName" 
          } 

        ] 
       ]; 
    //var grid = dijit.byId("gridDiv"); 
    //grid.setStore(store1); 

    var grid = new dojox.grid.DataGrid({ 

     store: store1, 
     structure: gridStructure, 
     rowSelector: '30px', 
     selectionMode: "single", 
     autoHeight:true, 
     columnReordering:true 

     },'gridDiv'); 

    grid.startup(); 
    dojo.connect(grid, "onRowClick", grid, function(){ 
       var items = grid.selection.getSelected(); 
       dojo.forEach(items, function(item){ 
        var v = grid.store.getValue(item, "ActID"); 
        getdetailsfordialog(v); 

        function showDialog() { 
         dojo.require('dijit.Tooltip'); 
         dijit.byId("terms").show(); 
        } 

        showDialog(); 
        }, grid); 

      }); 
} 

function sendmail(item) { 
    alert(item); 
     return "<button onclick=http://localhost:8080/2_8_2012/jsp/SendMailReminder.jsp?Send Mail="+item+"'\">Send Mail</button>"; 

    } 
function deleteact(item) { 
    alert(item); 
     return "<button onclick=http://localhost:8080/2_8_2012/jsp/DeleteActivity.jsp?Activity ID="+item+"'\">Delete</button>"; 
    } 
</script> 

我正在使用$.get調用網格數據。在上述代碼字段EmailActID實際上是在每個時間函數sendmaildeleteactformatter中被調用時創建的按鈕。網格顯示。兩個函數中的值alert(item)都是正確的,這就是各自的值。像在Deletealert(item)我在sendmail越來越"[email protected]"越來越ActIDalert(item)現在,我想,在一個特定的button click(在Sendmail欄按鈕),我的網頁

http://localhost:8080/2_8_2012/jsp/SendMailReminder.jsp?Send Mail="+item+"' 

button clickDelete列本頁面

http://localhost:8080/2_8_2012/jsp/DeleteActivity.jsp?Activity ID="+item+"'\" 

用從數據庫檢索的項目的值打開。我已經申請了一個rowClick事件也這也造成問題,因爲當我點擊你的按鈕我的Rowclick事件觸發,而不是按鈕點擊事件。這個怎麼做。我想到將點擊事件應用到網格上的每個按鈕。但是我不知道那裏有身份證。請幫我解決這個問題。謝謝..

+0

你是什麼意思'執行一些其他的JSP頁面上行動'?你想在彈出窗口中打開這個其他的JSP,還是發送一個Ajax請求來執行一些服務器端的動作或其他什麼? – ivalkeen 2012-04-22 18:23:01

+0

在那個JSP SendMailReminder.jsp。我有一個類的對象發送郵件。這個對象調用一個類的特定函數,它將一個郵件發送到從查詢字符串中的項目中收集的值。所以基本上我需要將這個值作爲參數傳遞給SendMailReminder.jsp中的被調用函數。或者我可以做的是隻在同一頁面上調用該方法,而不將其重定向到SendMailReminder.jsp。如果第二個可能,請給我一個方法來做到這一點?謝謝 – 2012-04-23 04:25:41

+0

而且,我一直在收到一個錯誤「試圖註冊一個id =」的東西,但該ID已經註冊「。我知道它是一個非常常見的錯誤,並且可以從dojo註冊表中刪除id。但我不清楚它是什麼。以及如何克服這一點。謝謝..我不接受我當前頁面中的這個錯誤(Ques被問到)。但不斷在其他網頁上獲得它。 – 2012-04-23 04:38:06

回答

1

我認爲,你需要的是調整你的服務器端代碼來處理ajax發送郵件的請求,並在用戶點擊按鈕時使用dojo.xhrPost方法。你的JS代碼可能會是這樣:

function sendMailHandler(evt, item) { 
    dojo.xhrPost({ 
     url: "/2_8_2012/jsp/SendMailReminder.jsp", 
     content: { 
     'SendMail': item 
     }, 
     error: function() { 
     alert("Sent failure"); 
     }, 
     load: function(result) { 
     alert("Email sent with result: " + result); 
     } 
    }); 

    dojo.stopEvent(evt); 
    } 

    function sendmail(item) { 
    return "<button onclick='sendMailHandler(arguments[0], \"" + item + "\")'>Send Mail</button>"; 
    } 

注意dojo.stopEvent(evt);sendMailHandler用於停止事件冒泡並防止RowClick認識。

還有dojo.xhrGet具有類似的語法來執行ajax GET請求,您可以使用它來代替jQuery的$.get。您還可以在我的例子中使用dojo.xhrGet代替dojo.xhrPost,因爲有機會,它會與你的後端工作,沒有扭捏,但POST(或AJAX表單提交)會更語義正確。

而關於「試圖註冊一個id =」東西」,你應該調整你的代碼,以避免編號重複,或者展示你的代碼導致錯誤。

+0

這工作得很好,在第一次嘗試.. :)謝謝很多先生..你可以幫助我與這個鏈接也是,新的dojo獲取probs ..再次感謝... http://stackoverflow.com/questions/ 10280815 /清爽,dojogrid – 2012-04-23 12:46:20