简体   繁体   中英

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.

I tested it without the SPServices and if I just do that function without SPServices it works. I also tested SPServices with alerts and not the variable, and those work fine too. 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");
            }
        }
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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