SPServices:如何进行调查?

时间:2014-09-08 13:53:43

标签: jquery web-services sharepoint spservices

我使用SharePoint进行了基本调查,但无法找到如何使用SPServices获取问题。

我只知道如何使用以下代码获取调查结果:

$().SPServices({
    operation: "GetListItems",
    webURL: "https://mysite.com/",
    listName: "SurveyMobileSP",
    CAMLQuery:"",
    error: function (xhr, message, error) {
        alert('Error : ' + error);
    },
    completefunc: function (xData, status) {
        console.log('Status: '+status+' xdata: ' + 'RESPONSE: ' + xData.responseText);
    });
});

1 个答案:

答案 0 :(得分:2)

Survey列表中,问题是一个字段。为了确定字段是问题字段还是常规字段,您可以使用SourceID属性,如果是qurstions,则其值为 http://schemas.microsoft.com/sharepoint/v3

如何使用SPServices从调查列表中检索问题

function getSurveyQuestions(complete) 
{
  $().SPServices({
    operation: "GetList",
    listName: "Survey",
    completefunc: function(xData, Status) {
      var questions = []; 
      $(xData.responseXML).find("Fields > Field[SourceID!='http://schemas.microsoft.com/sharepoint/v3']").each(function() {
        var $fieldNode = $(this).get(0);
        questions.push($fieldNode);
      });
      complete(questions);
    }
  });
}

用法

getSurveyQuestions(
  function(questions)
  {
     for(var i = 0; i < questions.length;i++) {
        console.log( "Question: " + $(questions[i]).attr("DisplayName"));         
     }  
  }
);