jQuery wrapper

Mar 24, 2010 at 4:00 PM
Edited Mar 24, 2010 at 4:02 PM
I wrote a set of small jQuery wrappers that look like: var defaultSiteUrl = 'https://default.site.url/pages/site/'; jQuery.getItems = function(options){ options = $.extend({ site:defaultSiteUrl, list:'', query:'<OrderBy><FieldRef Name="ID" Ascending="TRUE" /></OrderBy>', limit:1000, fields:'' // syntax: [{title:'Title',internalName:'LinkTitle'}] },options); var theList = jP.Lists.setSPObject(options.site, options.list); if(options.fields != '') theList.ViewFields = options.fields; options.callback(theList.getSPItemsWithQuery(options.query, options.limit).Items); }; So you can run a query like: $.getItems({ list:'Projects', limit:3, fields:[{internalName:'myField',title:'myField'}], query:'<OrderBy><FieldRef Name="ID" Ascending="FALSE" /></OrderBy>', callback:function(result){ if(!result) alert('no projects found!'); else{ for(property in result) alert(result[property].myField); } } }); Granted, arguably this is more lines than you would need to run this same query normally in jPoint, but I like the flow it has and it's easier for me to remember object properties than syntax, plus I can handle errors the same way globally for all operations of a certain type, or focus them locally to each callback function when needed. Just thought I'd throw this out there for any use/opinions/possible improvements.
Mar 24, 2010 at 4:02 PM
Apparently I'm missing something with formatting, hopefully someone can clean this up for me :[
Apr 9, 2010 at 5:13 AM

I like your method.  I will need to use it, possibly on my next project, to think about the pros and cons.  I've been thinking about using Aspect Orient Programming to be able to "insert" a error handler globally.  I was able to run your code, and got the same thing, no results.  I noticed, in Firebug, I was getting HTTP 500 errors and a web response saying the GUID was in the wrong format.  I'll need to look more into this.  If anybody else knows or has an idea here, please let us know.


Apr 9, 2010 at 5:35 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.