SP へGroupCollection オブジェクト (sp.js)

の SP のコレクションを表しますグループオブジェクトです。

**適用対象:**apps for SharePoint | SharePoint Foundation 2013 | SharePoint Server 2013

var object = new SP.GroupCollection()

メンバー

GroupCollectionオブジェクトでは、次のメンバーがあります。

Constructor

GroupCollectionオブジェクトでは、次のコンスがあります。

コンストラクター

説明

GroupCollection

Initializes a new instance of the SP.GroupCollection object.

メソッド

GroupCollectionオブジェクトでは、次の方法があります。

メソッド

説明

追加します。

Adds a group to the collection of groups in a site collection.

getById

Returns a group from the collection based on the member ID of the group.

getByName

Returns a cross-site group from the collection based on the name of the group.

itemAt

削除します。

Removes the specified group from the collection.

removeById

Removes the group with the specified member ID from the collection.

removeByLoginName

Removes the cross-site group with the specified name from the collection.

プロパティ

GroupCollectionオブジェクトでは、次のプロパティがあります。

プロパティ

説明

childItemType

アイテム

次の例では、現在の Web サイトの閲覧者グループに現在のユーザーを追加するアプリケーション ページの [入力] ボタンを作成します。

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script type="text/ecmascript" language="ecmascript">

var user;
var visitorsGroup;

function runCode() {

     var clientContext = new SP.ClientContext();
     var groupCollection = clientContext.get_web().get_siteGroups();
     // Get the visitors group, assuming its ID is 4.
     visitorsGroup = groupCollection.getById(4);
     user = clientContext.get_web().get_currentUser();
     var userCollection = visitorsGroup.get_users();
     userCollection.addUser(user);

     clientContext.load(user);
     clientContext.load(visitorsGroup);
     clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

}

function onQuerySucceeded() {
    alert(user.get_title() + " added to group " + visitorsGroup.get_title());
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

</script>

    <input id="Button1" type="button" value="Run Code" onclick="runCode()" />

</asp:Content>

他のリソースのエンドポイント

詳細については、 GroupCollection リソースを参照してください。

エンドポイント URI 構造

http://<sitecollection>/<site>/_api/web/sitegroups

HTTP 要求

このリソースには、次の HTTP コマンドがサポートしています。

書式を取得します。

GET http://<sitecollection>/<site>/_api/web/sitegroups

投稿の書式

POST http://<sitecollection>/<site>/_api/web/sitegroups