Jquery + Ajax:IE8上的变量未定义错误

时间:2015-05-11 08:44:20

标签: jquery ajax liferay yui

我的所有代码都适用于所有浏览器,但IE8中我得到一个变量未定义错误。我在Liferay 6.2中使用YUI3,Jquery和Ajax,变量(dataTable)是通过Alloy UI创建的数据表。这里是代码,也是出于某种原因,IE8忽略了通过YUI进行的所有dom操作。请注意,所有代码都在.JS文件中,我知道YUI代码通常在.JSP文件中,但为什么所有浏览器都能正常工作而不是IE8?

function loadSollicitudDataGrid(value)
{
xmlObject = loadXMLObject(value);
dataStore = loadDataStore(xmlObject,1);

YUI({ lang: 'ca-ES' }).use(
        'aui-node',
        'aui-datatable',
        'aui-pagination',
        'datatype-date',

        function(Y) {

            var truncate = function (o) {
                var trunc = '';
                if (o.value == "No") {
                 trunc = '';
                } else {
                    trunc = '<i class="icon-bolt icon-1x"></i>';
                }
                return trunc;
            };

            function formatDate(cell) {
                return Y.DataType.Date.format(new Date(cell.value), { format: '%d/%m/%Y' });
            }

            var nestedCols = [             
                {
                key:'DocumentIdTr',
                sortable: true
                },

                {
                key:'Titol',
                label:'Títol',
                sortable: true
                },

                {
                key:'Urgent',
                allowHTML: true,
                formatter: truncate,
                label:'Urgent'
                },

                {
                key:'Codi_Sollicitud',
                label: 'Codi Sol·licitud',
                sortable: true
                },

                {
                key:'Data_Alta',
                label: 'Data alta',
                sortable: true,
                formatter: formatDate
                }

            ];

            numDataTable = document.getElementById("myDataTable").childNodes.length;

            if (numDataTable > 0){
                dataTable.set('data', dataStore);
            } else {
                dataTable = new Y.DataTable (
                          {
                            columns: nestedCols,
                            data: dataStore,
                            plugins: [
                                  {fn: Y.Plugin.DataTableHighlight}
                            ],
                            rendered: true
                          }
                    ).render("#myDataTable");
            }

            //Control de Mensaje Alerta
            var alerta  = document.getElementById("myAlert");

            if (entradas.length <= 0){
                alerta.style.display = 'block';
            } else {
                alerta.style.display = 'none';
            }

             //Añadimos clases a la tabla para poder customizarla//
             var nodeObject = Y.one('#myDataTable table');
             nodeObject.removeClass('table-table');
             nodeObject.addClass('table');
             nodeObject.addClass('mytable');
             nodeObject.addClass('table-hover');

             /*Asignamos id's a las columnas de las tablas*/
             var documentIdTr = Y.one('#myDataTable table thead tr th:nth-child(1)');
             var titol = Y.one('#myDataTable table thead tr th:nth-child(2)');
             var urgent = Y.one('#myDataTable table thead tr th:nth-child(3)');
             var codi_solicitud = Y.one('#myDataTable table thead tr th:nth-child(4)');
             var data_alta = Y.one('#myDataTable table thead tr th:nth-child(5)');
             documentIdTr.addClass('DocumentIdTr_col');
             titol.addClass('titol_col');
             urgent.addClass('urgent_col');
             codi_solicitud.addClass('codi_solicitud_col');
             data_alta.addClass('data_alta_col');

             dataTable.delegate('click',function(ev) {
                var target = ev.currentTarget, 
                //modelList = this.get('data'),
                columns = this.get('columns'),
                //cellIndex = Y.Node.getDOMNode(target).cellIndex,
                rid = target.get('id'),
                r1 = this.getRecord(rid);
                var selectedColumn = columns[0].key;   
                var selectedCell = r1.get(selectedColumn); 

                var petId = selectedCell;
                DWRUtil.setValue("frmConsulta:id",petId);
                document.getElementById("frmConsulta:botoConsulta").click();   

            },".table-cell",dataTable);


            function esVisible() {
                var num_page = document.getElementById("numResultsPage").value;
                var visible = false;

                if (num_page < entradas.length && entradas.length > 0) {
                    visible = true;
                }
                return visible;
            }

            new Y.Pagination(
                {
                    boundingBox: '#pagination',
                    circular:false,
                    contentBox:'#pagination .pagination-content',
                    page: 1,
                    visible: esVisible(),
                    on: {
                        changeRequest: function(event) {
                            dataTable.set('data', loadDataStore(xmlObject,event.state.page));
                        }
                    },
                    total:number_of_pages
                 }
                 ).render();



              Y.one('.pagination-content .pagination-control:first-child').setHTML('<div><i class="icon-chevron-left icon-1x"></i></div>');   
              Y.one('.pagination-content .pagination-control:last-child').setHTML('<div><i class="icon-chevron-right icon-1x"></i></div>');
              //Ocultamos paginaci�n interna (1,2,3..etc)
              Y.all('.pagination-content li:nth-of-type(n+2):nth-last-of-type(n+2)').addClass('ocultar');
              ocultar = Y.all('.ocultar');
              ocultar.setStyle('display','none');
              prev = Y.one('.pagination-content li:first-child');
              next = Y.one('.pagination-content li:last-child');
              prev.setStyle('cursor','pointer');
              next.setStyle('cursor','pointer');                

          }
        );


return "";

}

1 个答案:

答案 0 :(得分:1)

好的,这就像我想的那样简单。出于某种原因,当您使用以下方法初始化Alloy UI时,所有现代浏览器(包括IE9)都没有任何问题:

YUI({ lang: 'ca-ES' }).use(
    'aui-node',
    'aui-datatable',
    'aui-pagination',
    'datatype-date',

    function(Y) {...

但IE8(当然)会给你一系列非常奇怪的控制台错误,并且如果你不使用YUI的AUI,你的小部件会工作不好,所以就是我在我的所有部分用AUI取代了YUI代码,现在在IE8中工作正常。如果有人可以提供正确的解释将非常感激,因为我很难理解为什么IE8不能正常使用YUI初始化Alloy UI小部件或使用YUI。