2009-12-15 31 views
0

我在面板對話框中有一個數據表。數據表顯示ok ...但是....沒有事件正在註冊,喜歡排序,行選擇等等。不是香腸。如果數據表不在面板內,那麼行選擇,排序等工作就會很好。YUI數據表在面板中沒有註冊事件

這是我的代碼。如果你能指引我朝着正確的方向,我將永遠感激不盡。

YAHOO.util.Event.addListener(window, "load", function(){ 
function processPostpone(e) 
{ 
     var dom = YAHOO.util.Dom; 
     if(dom.get("user_rejected").value==3) 
     { 
      window.alert(dom.get("user_rejected_impossible").value); 
     } 
     else 
     { 
      var elTarget = YAHOO.util.Event.getTarget(e);  
      var attendance_id = elTarget.id; 
      attendance_id = attendance_id.substring(7, 15); 
      var handleYes = function() { 
       // postpone session 
       var callback = { 
        success : function(o) 
        { 
         if(o.responseText=="true") 
         { 
          // succesfully postponed session 
          var callback2 = 
          { 
            success: function(o) 
            { 
             try 
             { 
              messages = YAHOO.lang.JSON.parse(o.responseText); 
             } 
             catch (x) 
             { 
              alert("JSON Parse failed!"); 
              return; 
             } 
             if(messages.ResultSet.count > 0) 
             { 
              // there are some other available sessions 
              var columndefs = [ 
                   {key:"name", label: "Session", sortable:false, resizeable:false}, 
                   {key:"location", label: "Location", sortable:false, resizeable:false}, 
                   {key:"start_date", label: "Start Date", sortable:false, resizeable:false} 
                  ]; 

              var datasource = new YAHOO.util.DataSource(messages); 
              datasource.responseType = YAHOO.util.DataSource.TYPE_JSON; 
              datasource.responseSchema = { 
                resultsList: "ResultSet.Result", 
                fields: ["name","location","start_date"] 
              }; 

              var datatable = new YAHOO.widget.DataTable("possibleSessionsDataTable", columndefs, datasource, {rowSingleSelect:true, zindex:999}); 
              datatable.subscribe("rowMouseoverEvent", datatable.onEventHighlightRow); 
              datatable.subscribe("rowMouseoutEvent", datatable.onEventUnhighlightRow); 
              datatable.subscribe("rowClickEvent", datatable.onEventSelectRow); 
              datatable.focus(); 

              var handleSubmit = function() { 
               // test 
               alert('You clicked submit'); 
              } 

              var panel = new YAHOO.widget.Panel("panel2", { width:"600px", visible:false, modal: false, fixedCenter: true, draggable:false, close:false }); 
              panel.setHeader("Other Sessions You May Be Able To Attend"); 
              panel.setBody(dom.get("other_possible_sessions").innerHTML); 
              panel.setFooter('<div id="panelFooter"></div>'); 

              panel.showEvent.subscribe(function() { 
               var button1 = new YAHOO.widget.Button({ 
                type: 'button', 
                label: 'Submit', 
                container: 'panelFooter' 
               });               
               button1.on("click", handleSubmit); 
              }, panel, true); 

              panel.render("container"); 
              panel.show(); 
             } 
            }, 
            failure: function(o) 
            { 

            } 
           } 
           var conn = YAHOO.util.Connect.asyncRequest("POST", "/ajax/possiblesessions.json?id=" + attendance_id, callback2); 
          } 
          else 
          { 
           window.alert("Sorry, there was an error."); 
          } 
         }, 
         failure : function(o) 
         { 
          window.alert("Sorry, there was an error."); 
         } 
        } 
       var conn = YAHOO.util.Connect.asyncRequest("POST", "/ajax/postponesession.json?id=" + attendance_id, callback); 

       var loading = new YAHOO.widget.Panel("wait", 
         { width:"300px", 
          fixedcenter:true, 
          close:false, 
          draggable:true, 
          zindex:4, 
          modal:false, 
          visible:false 
         } 
        ); 
      this.hide(); 

      /*loading.setHeader("Rejecting session..."); 
      loading.setBody('<img src="http://l.yimg.com/a/i/us/per/gr/gp/rel_interstitial_loading.gif" />'); 
      loading.render(document.body); 
      loading.show();*/ 
      }; 

      var handleNo = function() { 
       this.hide(); 
      }; 

      var dialog = new YAHOO.widget.SimpleDialog("dialog", 
         { width: "300px", 
          fixedcenter: true, 
          visible: false, 
          draggable: false, 
          close: true, 
          text: document.getElementById("reject_alert_text").innerHTML, 
          modal: false, 
          icon: YAHOO.widget.SimpleDialog.ICON_HELP, 
          constraintoviewport: true, 
          buttons: [ { text:"Yes", handler:handleYes, isDefault:true }, 
             { text:"No", handler:handleNo } ] 
         }); 
      dialog.setHeader("Reject session?"); 
      // Render the Dialog 
      dialog.render(document.body); 
      dialog.show(); 
     } 
} 
// create postpone button 
var elms = YAHOO.util.Dom.getElementsByClassName("reject"); 

// loop over all the elements and attach a click event 
for(var i=0,j=elms.length;i<j;i++) 
{ 
    var el = document.getElementById(elms[i].id); 
    YAHOO.util.Event.addListener(el, "click", processPostpone); 
} 

var tabView = new YAHOO.widget.TabView('tabs'); 

});

我爲長碼片斷表示歉意。

預先感謝您。

回答

1

儘管我無法從您提供的代碼片段中確切地知道問題,但我會採取合理的猜測,並建議您可能正在處理範圍問題。

換句話說,可能不是沒有事件被觸發,而是附加到它們的函數超出範圍,或者由於超出範圍變量而導致函數中的回調失敗。 (YUI有時可以通過事件來抑制錯誤)

很多yui函數都有第三個和第四個參數讓我們指定回調在其中執行的範圍。

obj.subscribe("onEvent", this.onEvent, this, true); 

上面的代碼片段將onEvent中的'this'設置爲當前值,可能是當前對象。

我會首先看看您的回調函數執行的範圍。嘗試console.log(this);你可能會發現這不是你所期待的。

+0

非常好。我會放棄這一點。非常感謝你:-) – Flukey 2009-12-16 13:32:39

+0

因此增加了一個範圍: \t \t \t \t \t \t \t \t datatable.subscribe( 「radioClickEvent」 功能(oArgs){ \t \t \t \t \t \t \t警報('你好單選按鈕點擊!'); \t \t \t \t \t \t \t},panel,true); 但是,唉,即使範圍是爲面板....它不喜歡它:-(我非常困惑和惱火。謝謝:-) – Flukey 2009-12-16 14:03:42

+0

傑米,只是想知道如果你曾經解決過這個問題?我正在面對類似的問題,在一個yui3標籤視圖內的tableView中表現得有點奇怪。謝謝 - 巴特 – 2010-07-28 21:04:05