对象不支持属性错误尝试"每个"环

时间:2014-11-13 04:00:29

标签: jquery sharepoint-2010

它正在努力我需要通过列表项进行迭代,即" SP.SPFilterNode(" z:row")。each(function()" I& #39;已经尝试了它现在的位置,在成功回调中,附加了SchedRec,listItems和这个版本....没有用。我怎么能用.each循环遍历项目(在这种情况下有6条记录)

function A(THePWD) {
//Count Exam Objectives
var deferred = $.Deferred();
console.log("A " + THePWD);

var clientContext = null; 
var currentweb = null; 
clientContext = new SP.ClientContext.get_current(); 
web = clientContext.get_web(); 
var SchedRec = web.get_lists().getByTitle("Exam Objectives"); 
var camlQuery = new SP.CamlQuery(); 
var q = "<View><Query><Where><Gt><FieldRef Name='ID' /><Value Type='Number'>" + 0 + "</Value></Gt></Where></Query></View>" 
camlQuery.set_viewXml(q); 
var listItems = SchedRec.getItems(camlQuery); 
clientContext.load(listItems, 'Include(Title)'); 
var o = {deferred: deferred, listItems: listItems};

clientContext.executeQueryAsync(
            Function.createDelegate(o, this.OnFindSchedLoadSuccessA), 
            Function.createDelegate(o, this.OnFindSchedLoadFailed)
            );


SP.SPFilterNode("z:row").each(function() { 
console.log  ($(this).attr("ows_Title"));
});

return deferred;
} 

function  OnFindSchedLoadSuccessA(sender, args){
var def = $.Deferred();

if (this.listItems.get_count() >0) {
    console.log("A: total objectives=" + this.listItems.get_count());
   /* this.listItems.each(function() {
    console.log ($(this).attr("ows_Title"));
  });*/     
    this.deferred.resolve();        
}else {
    console.log("REJECTED funcA");
    this.deferred.reject("count zero");
    }
return def;
}

1 个答案:

答案 0 :(得分:0)

部分错误是我的'SP',而'新SP.ClientContext.get_current(); ',与SPServices不同。所以我发现需要包含SPServices js文件,如下所示。

<script language="javascript" src="https://<my sharepoint site>/Site Assets/jquery.SPServices-2014.01.min.js" type="text/javascript"></script> 

THEN .... 以下代码示例用于调整我的需求:

 var method = "GetListItems";
    var list = "Exam Objectives";

    var fieldsToRead = "<ViewFields>" +
                                      "<FieldRef Name = 'Title' />" +
                                       "<FieldRef Name = 'ID' />" +
                                    "</ViewFields>";
    var query = "<Query>" +
                          "<Where>" +
                            "<Neq>" +
                              "<FieldRef Name='ID' /><Value Type='Number'>0</Value>" +
                            "</Neq>" +
                          "</Where>" +
                          "<OrderBy>" +
                            "<FieldRef Name='Title'/>" +
                          "</OrderBy>" +
                        "</Query>";
    $().SPServices({
      operation: method,
      async: false,
      listName: list,
      CAMLViewFields: fieldsToRead,
        CAMLQuery: query,
          //this basically means "do the following code when the call is complete"
          completefunc: function (xData, Status) {
            console.log("pre-the zero index of Obj_Array is " + Obj_Array[0]);
            //this code iterates through every row of data returned from the web service call
            $(xData.responseXML).SPFilterNode("z:row").each(function() {
              Obj_Array.push($(this).attr("ows_Title"));
              Obj_Array[0]++;
              Random_Array.push(Obj_Array[0]);
              console.log(Obj_Array[Obj_Array[0]]);
            });
           console.log("post-the zero index of Obj_Array is " + Obj_Array[0]);

          }
    });