简体   繁体   English

变量不适用于SPServices

[英]Variable not working with SPServices

I'm having an issue with my variable. 我的变量有问题。 I'm not sure if it is syntax related, but for some reason the first part of my if statement with my variable will not work. 我不确定它是否与语法有关,但是由于某种原因,带有变量的if语句的第一部分将无法工作。

I tested it without the SPServices and if I just do that function without SPServices it works. 我在没有SPServices情况下对其进行了测试,如果我只是在没有SPServices情况下进行了该功能,则它可以正常工作。 I also tested SPServices with alerts and not the variable, and those work fine too. 我还用警报而不是变量测试了SPServices ,它们也可以正常工作。 Please see code below, any help is appreciated. 请查看下面的代码,我们将为您提供任何帮助。 Thanks! 谢谢!

$(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");
            }
        }
    });
});

never mind. 没关系。 i realized i was declaring the variable outside of the function i wanted to use it under. 我意识到我在函数要声明的函数之外声明了变量。 code should be written as so: 代码应这样写:

$(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");
            }
        }
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM