Коллекция Sharepoint 2010 не инициализируется

Просто измените url на http://localhost вместо localhost. Если вы откроете файл html из локального, вы должны создать локальный сервер для работы с этим html-файлом, самый простой способ - Web Server for Chrome . Это устранит проблему.

0
задан Aleksandar Stevcic 13 July 2018 в 15:26
поделиться

1 ответ

Здесь вы идете.

<script type="text/javascript">
        ExecuteOrDelayUntilScriptLoaded(getUserGroup, "sp.js");

        //found online
        function getUserGroup() {
            var context = new SP.ClientContext.get_current();
            var web = context.get_web();
            context.load(web);

            var currUser = web.get_currentUser();
            context.load(currUser);

            var groups = web.get_siteGroups();
            context.load(groups);

            context.executeQueryAsync(
                Function.createDelegate(this,
                    function () {

                        var isInGroup = false;
                        var groupEnumerator = groups.getEnumerator();

                        while (groupEnumerator.moveNext() && !isInGroup) { //go through all the groups
                            var oGroup = groupEnumerator.get_current(); //get current group in the enumerator

                            if (oGroup.get_title() == "SPM Team") { //is the group title named this?
                                var collUser = oGroup.get_users(); //get all the users in the group

                                context.load(collUser);
                                context.executeQueryAsync(
                                    Function.createDelegate(this,
                                        function () {
                                            var userEnumerator = collUser.getEnumerator(); //get the enumeration
                                            while (userEnumerator.moveNext() && !isInGroup) { //go through all users in group
                                                oUser = userEnumerator.get_current(); //get current user in the enumerator
                                                if (oUser.get_id() == currUser.get_id()) { //is the user's id the same as the viewer?
                                                    isInGroup = true;
                                                    console.log("success");
                                                }
                                            }
                                        }),
                                    Function.createDelegate(this,
                                        function (sender, args) {
                                            console.log(args);
                                        }));

                            }
                        }
                    }),
                Function.createDelegate(this,
                    function OnFailure() {
                        console.log("nope");
                    }));
        }
    </script>
0
ответ дан Lee_MSFT 17 August 2018 в 12:30
поделиться
  • 1
    Спасибо! У меня есть один вопрос, хотя, если один из моих «пользователей» является группой в пределах этой группы разрешений, как я буду продолжать расширять ее дальше? В этом случае команда «SPM» у группы есть несколько пользователей, а затем другая группа, которая содержит всю команду SPM, как своего рода псевдоним. – Aleksandar Stevcic 16 July 2018 в 15:16
  • 2
    Для расширения вы можете добавить параметры в свою настраиваемую функцию на основе параметров, добиться различной логики. [Д0] sharepoint.stackexchange.com/questions/39731/… – Lee_MSFT 17 July 2018 в 01:34
Другие вопросы по тегам:

Похожие вопросы: