0

I am using SPServices to get the list items I want returned to me from a specific list. I know how to find a particular element using this the GetListItems function without a problem. Is there a way to loop through all of the z:row elements and store all of the returned ows_ values in an array?

$(xData.responseXML).SPFilterNode("z"row").each(function(){
    //I know this is how to get it by calling it directly

      var xitem = $(this);
      var title = xitem.attr("ows_Title");

   //Is there a way to get them all at once?

});

Any help would be much appreciated! Thanks!

1 Answer 1

1

Try this

jQuery().SPServices({
    operation: "GetListItems",
    async: false,
    listName: listName,
    CAMLViewFields: "<ViewFields><FieldRef Name='Values'/></ViewFields>",
    completefunc: Function.createDelegate(this, callback)
});

callback = function (xData, Status) {
    var values = new Array();
    jQuery(xData.responseXML).SPFilterNode("z:row").each(function() {           
        values.push(jQuery(this).attr('Values'));
    });
};

Update

jQuery(xData.responseXML).SPFilterNode("z:row").each(function() {   
    jQuery.each(this.attributes, function(i, attrib) {
        values.push(attrib.value);
    }
});
2
  • Thanks but ows_Values is not a literal return. I will fix my question. I need to get all pf the elements in each z:row all of the ows_whatevertheyare elements. Thanks for the response.
    – lazoDev
    Commented Dec 23, 2014 at 17:58
  • @lazoDev: See my updated answer. The code is not tested. So you might need to fix here and there, but the concept will work for sure. Commented Dec 23, 2014 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.