2

我使用 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);
    });
});
4

1 回答 1

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"));         
     }  
  }
);
于 2014-09-09T16:47:17.293 回答