使用SPServices在sharepoint2010中读写列表数据

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用SPServices在sharepoint2010中读写列表数据相关的知识,希望对你有一定的参考价值。

Just syntax examples here. First block reads, second writes. Top function just a debugging helper.

Using jquery 1.5, $(xData.responseXML).find("nodeName=z:row]").each(function(i)... may need to be written as
$(xData.responseXML).find("nodeName='z:row']").each(function(i)... with single quotes around 'z:row'.
  1. function printObject(o){
  2. var output = '';
  3. for (property in o) {
  4. output += property + ': ' + o[property]+'; ';
  5. }
  6. alert(output);
  7. }
  8.  
  9.  
  10.  
  11.  
  12. function readThenWrite(){
  13.  
  14.  
  15.  
  16. $().SPServices({
  17. operation: "GetListItems",
  18. webURL: "/sitepath", /*optional parameter used if list lives in parent site */
  19. async: false,
  20. listName: "Badge Achievements", /*name of the list */
  21. viewName: '{D6ED584C-4673-4B89-B539-FF43D936ABC9}',/*optional to specify view */
  22. CAMLRowLimit: 4, /*optional to limit results */
  23. CAMLQuery: '<Query><Where><Eq><FieldRef Name="Author" /><Value Type="User">' + userName + '</Value></Eq></Where></Query>',
  24. completefunc: function (xData, Status) {
  25. //printObject(xData);
  26. $(xData.responseXML).find("[nodeName=z:row]").each(function(i) {
  27. arrBadgesAchvd[i] = $(this).attr('ows_Badge').split("#")[1];
  28. });
  29. }
  30.  
  31. });/*-End SpServices*/
  32.  
  33.  
  34.  
  35.  
  36. $().SPServices({
  37. operation: "UpdateListItems",
  38. async: false,
  39. listName: "Learning Path Completion",
  40. updates: "<Batch OnError='Continue'>" +
  41. "<Method ID='1' Cmd='Update'>" +
  42. "<Field Name='Title'>percDone</Field>" +
  43. "<Field Name='User'>" + userID + "</Field>" +
  44. "<Field Name='Completed'>" + lpdone + "</Field>" +
  45. "<Field Name='Total'>" + lptotal + "</Field>" +
  46. "<Field Name='ID'>" + docid + "</Field>" +
  47. "</Method>" +
  48. "</Batch><Where></Where>",
  49. completefunc: function(xData, Status) {}
  50. });//End SPSErvices
  51.  
  52.  
  53.  
  54.  
  55. }/*End readThenWrite*/

以上是关于使用SPServices在sharepoint2010中读写列表数据的主要内容,如果未能解决你的问题,请参考以下文章

SharePoint 2010使用SPServices获取用户标识

具有CAML查询的SharePoint级联下拉列表可过滤其中一个选项

SharePoint 2013 使用 JavaScript 获取当前用户

SharePoint List来做项目管理

Sharepoint:限制caml查询中的结果

如何在打字稿中导入js文件作为模块