面板中的 YUI 数据表未注册事件

发布于 2024-08-15 12:26:33 字数 7909 浏览 5 评论 0原文

我在面板对话框中有一个数据表。数据表显示正常...但是...没有事件被注册,喜欢排序,行选择等。什么都没有。不是香肠。如果数据表不在面板内,则行选择、排序等工作完全正常。

这是我的代码。如果您能为我指出正确的方向,我将永远感激不已。

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');

});

我对长代码片段表示歉意。

先感谢您。

I have a datatable within a panel dialog. The datatable displays ok...however....no events are being registered, liked sort, row selection etc. Nothing at all. Not a sausage. If the datatable is not inside a panel then row selection, sorting etc. works perfectly fine.

Here is my code. I would be forever grateful if you could point me in the right direction.

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');

});

I apologise for the longcode snippet.

Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人│生佛魔见 2024-08-22 12:26:33

尽管我无法从您提供的代码片段中说出确切的问题,但我会进行有根据的猜测,并建议您可能正在处理范围问题。

换句话说,可能不是没有事件被触发,而是附加到它们的函数超出了范围,或者回调中的功能由于超出范围的变量而失败。 (YUI 有时可以抑制事件错误)

许多 yui 函数采用第三个和第四个参数,让您指定回调执行的范围。

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

上面的代码片段将 onEvent 中的“this”设置为 this 的当前值,可能是当前对象。

我首先查看回调函数执行的范围。尝试 console.log(this);您可能会发现这不是您所期望的。

Although I can't tell the exact problem from the code snippet you have provided I'll take an educated guess and suggest you are probably dealing with scope issues.

In other words it might not be that there are no events being fired but rather the functions attached to them are out of scope, or the functionally in the callbacks is failing because of out of scope variables. (YUI can sometimes suppress errors with events)

Many yui functions take a third and forth argument that let's you specify the scope the callback is executed in. eg.

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

The above snippet will set 'this' in onEvent to the current value of this, probably the current object.

I would start by looking at the scope your call back functions are executed under. Try console.log(this); You may find it's not what you where expecting.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文