Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取对象的所有属性-不在IE中工作_Javascript_Jquery_Internet Explorer_Sharepoint 2010_Attributes - Fatal编程技术网

Javascript 获取对象的所有属性-不在IE中工作

Javascript 获取对象的所有属性-不在IE中工作,javascript,jquery,internet-explorer,sharepoint-2010,attributes,Javascript,Jquery,Internet Explorer,Sharepoint 2010,Attributes,在下面的代码中,我包含了一个用于调试的属性。在FF和Chrome中,我收到大量的警报,说找到了属性,但在IE中,我什么也没有得到。函数返回一个空数组 我还尝试删除了console.info这一行 顺便说一句,我正在使用SPServices从SharePoint 2010访问列表-我正在尝试获取列表的所有列 /*! * listAttributes jQuery Plugin v1.1.0 * * Copyright 2010, Michael Riddle * Licensed unde

在下面的代码中,我包含了一个用于调试的属性。在FF和Chrome中,我收到大量的警报,说找到了属性,但在IE中,我什么也没有得到。函数返回一个空数组

我还尝试删除了console.info这一行

顺便说一句,我正在使用SPServices从SharePoint 2010访问列表-我正在尝试获取列表的所有列

/*!
 * listAttributes jQuery Plugin v1.1.0
 *
 * Copyright 2010, Michael Riddle
 * Licensed under the MIT
 * http://jquery.org/license
 *
 * Date: Sun Mar 28 05:49:39 2010 -0900
 */

 //THIS ISN'T WORKING IN IE
if(jQuery) {
    jQuery(document).ready(function() {
        jQuery.fn.listAttributes = function(prefix) {
            var list = [];
            var attributes = [];
            $(this).each(function() {
                console.info(this);
                for(var key in this.attributes) {
                alert("attribute found");
                    if(!isNaN(key)) {
                        if(!prefix || this.attributes[key].name.substr(0,prefix.length) == prefix) {
                            attributes.push(this.attributes[key].name);
                        }
                    }
                }
                list.push(attributes);
            });
            return attributes;
        }
    });
}
//end listAttributes Plugin - use this to see what attributes 


function ImportSPListColumnsToArray(ListName)
{
    var ArrayForStorage = new Array();
$(document).ready(function() {


  $().SPServices({
    operation: "GetListItems",
    async: false,
    listName: ListName,
    CAMLViewFields: "",
    CAMLQueryOptions: "<QueryOptions><ViewAttributes Scope='RecursiveAll'/></QueryOptions>",
    **completefunc: function (xData, Status) {
      $(xData.responseXML).find("[nodeName='z:row']").each(function() {
      //find all fields used by each row and aggregate them without duplicating
      var row_attr = $(this).listAttributes();**
      for (var i=0; i<row_attr.length; i++)
        {
            if ($.inArray(ArrayForStorage, row_attr[i]) == -1)
                {
                    ArrayForStorage.push(row_attr[i]);
                }
        }
      row_attr.clear();
      });
    }
  });

});
  return ArrayForStorage;

}

我可能错了,但我相信你的问题在于安慰;线IE没有现成的脚本,所以您的脚本在这一点上失败了

找到了答案

IE显然不认为这个.attributes在for each循环中有一个长度

所以我只是重复了一遍,结果成功了

if(jQuery) {
        jQuery.fn.listAttributes = function() {
            var attributes = new Array();
            $(this).each(function() {
                for (var i=0; i<this.attributes.length; i++)
                {
                    attributes.push(this.attributes.item(i).nodeName);
                }
            });
            return attributes;
        }
}

我打开了开发人员工具,并尝试删除该行。没有更改…与您的问题无关,但仅供参考:在$document.ready中声明插件是不寻常的。在全局范围内声明它更为常见。而且当你使用$this时。每个。。。这将已经是一个jQuery对象,因此您可以并且应该只使用this.eachWhat is.listAttributes;?我不认为它是jQuery库的一部分。对不起,我只看到了部分代码。@bfavaretto这就是为什么Christian有jQuery.fn.listAttributes=functionprefix{…}@Matt-这是DOM元素。例如this.hide将不会只起作用$this.hide将-示例this:$this----最好的做法是缓存$this=>@Peter:在他使用$this.each的情况下,这指向他调用listAttributes的jQuery对象: