Tonight I posted the first (we always hope the only) beta for SPServices v0.7.0. Initially I was calling this release v0.6.3, but when jQuery 1.7 was released and it caused problems with SPServices, I decided to bump the version so that the sevens matched. Get it? 1.7 and v0.7.0? Such are the complex decisions we make about software version numbering. (Those of you who wonder why I still am using sub- version 1.0 numbering – it’s just because I feel like it. No real reason.)
One of the biggest things in this new beta is compatibility with jQuery 1.7. In a previous post, I talked about the fact that the .find("[nodeName='z:row']") syntax no longer worked with jQuery 1.7. This was a real annoyance, but due to some great work by Steve Workman, I think there’s an even better selection method in v0.7.0. Unfortunately, if you’d like to move to jQuery 1.7 in your environment, you’ll have to change the syntax in all of your code as well. What the jQuery team decides to change is out of my hands, of course, so occasionally this sort of thing will happen.
There’s an new function in SPServices called SPFilterNode, which is really quite simple, but it solves the problem, based on Steve’s work.
// This method for finding specific nodes in the returned XML was developed by Steve Workman. See his blog post
// http://www.steveworkman.com/html5-2/javascript/2011/improving-javascript-xml-node-finding-performance-by-2000/
// for performance details.
$.fn.SPFilterNode = function(name) {
return this.find('*').filter(function() {
return this.nodeName === name;
});
};
Here is an example of the syntax for calling this new function:
$(xData.responseXML).SPFilterNode("z:row").each(function() {
There are several benefits to having this function. First, it works in jQuery 1.7 as well as an earlier versions, going back at least to version 1.4.2, which is as far back as I tested. Second, as you can see if you read through Steve’s benchmarking results, it’s very efficient, even more efficient than the .find("[nodeName='z:row']") syntax. Third, if there is a change like this in a future version of jQuery, I can simply replace the function’s workings and all will continue to function well. Note that you only need to use SPFilterNode, and the .find("[nodeName='z:row']") syntax for that matter, when SharePoint’s Web Services return namespaced elements in the XML *and* you want to ensure cross-browser compatibility. If the nodes have names like “item” or “region”, or any other simple name which isn’t preceded with something and a colon, then .find(“item”) or .find(“region”) works fine. Of course, SPFilterNode will also work, but it’s not necessary.
If you are using SPServices and can do some regression testing, I’d certainly appreciate it, as will the other almost 8000 people who have downloaded SPServices v0.6.2 and may want to upgrade. Just be sure that you use the new SPFilterNode function if you are retrieving data from GetListItems with jQuery 1.7 or else it will seem as though you aren’t get anything back from the call.
I’ll publish the rest of the release notes when I release a stable version of v0.7.0, but if you’d like to see what’s in this version, check out the download page. As usual, it’s a mix of bug fixes, performance enhancements, and new features,.
3 comments
1 ping
Theater Balcony
December 6, 2011 at 2:51 am (UTC -5)
Hi Marc, Thank you for your time for spending time on this however I got a problem with my sharepoint site, I used your code, and I am not sure, what is the problem in my code, If you will get some time plz have a look at it.
I am getting an error like jQuery undefined. I used the following code,
var groupName;
$().SPServices({ operation: “GetGroupCollectionFromUser”, userLoginName: $().SPServices.SPGetCurrentUser(), async: false, completefunc: function(xData, Status) { alert(xData.responseXML.xml); $(xData.responseXML).SPFilterNode(“[nodeName=Group]“).each(function() {
groupName = $(this).attr(“Name”); }); } });
if($.trim(groupName) != ‘Ms g’)
{
document.getElementById(‘s4-leftpanel’).style.display = ‘none’;
}
Marc
December 6, 2011 at 7:13 am (UTC -5)
Theater:
Your error indicates that you don’t have a valid reference to the jQuery library.
M.
Theater Balcony
December 8, 2011 at 8:31 am (UTC -5)
Thank you very much Marc, After I referenced the latest JQuery library in my site, I got my jquery worked!! Thank you for spending time on this. Any ways fantastic work from you!!
Sharepoint Updates November-24-2011 | SDavara's Sharepoint Knowledge Center
November 25, 2011 at 1:28 am (UTC -5)
[...] English jQuery Library for SharePoint Web Services (SPServices) v0.7.0 Beta 1 Available [...]