变量不适用于SPServices

时间:2016-10-31 14:26:19

标签: jquery sharepoint-2013 spservices

我的变量存在问题。我不确定它是否与语法相关,但出于某种原因,我的if语句的第一部分与我的变量不起作用。

我在没有SPServices的情况下对其进行了测试,如果我只是在没有SPServices的情况下执行该功能,则可以正常运行。我还测试了SPServices警报而不是变量,这些也很好。请参阅下面的代码,任何帮助表示赞赏。谢谢!

$(document).ready(function(){
    var dropdown = $("select[title='Item-Status']");
    $().SPServices({ 
        operation: "GetGroupCollectionFromUser",
        userLoginName: $().SPServices.SPGetCurrentUser(),
        async: false,
        completefunc: function(xData, Status) {             
            if ($(xData.responseXML).find("Group[Name='CCB Team']").length == 0) {
                dropdown.find("option[value='QA Review']").remove();  
            } else if ($(xData.responseXML).find("Group[Name='QA Team']").length == 1) { 
                alert("You should see this");
            }
        }
    });
});

1 个答案:

答案 0 :(得分:0)

没关系。我意识到我在我想要使用它的函数之外声明变量。代码应该写成:

$(document).ready(function(){
     $().SPServices({ 
        operation: "GetGroupCollectionFromUser",
        userLoginName: $().SPServices.SPGetCurrentUser(),
        async: false,
        completefunc: function(xData, Status) {
            var dropdown = $("select[title='Item-Status']");
            if ($(xData.responseXML).find("Group[Name='CCB Team']").length == 0) {
                dropdown.find("option[value='QA Review']").remove();  
            } else if ($(xData.responseXML).find("Group[Name='QA Team']").length == 1) { 
                alert("You should see this");
            }
        }
    });
});