다음을 통해 공유


SP.Web.getSubwebsForCurrentUser(query_) Method

Applies to: SharePoint Foundation 2010

In this article
Return Value
Applies To
Remarks

Returns the collection of child sites of the current site based on the specified query.

var value = SP.Web.getSubwebsForCurrentUser(query_);

Parameters

  • query_
    Specifies which child sites to return.

Type: SP.SubwebQuery

Return Value

Type: SP.WebCollection

Applies To

SP.Web Class

Remarks

If the query is not valid, the server must return an empty collection.

Example

The following example creates an input button on an application page that displays the titles of the child sites of the current site.

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

    var webCollection = null;
    function runCode() {

        var clientContext = new SP.ClientContext.get_current();
        if (clientContext != undefined && clientContext != null) {
            var web = clientContext.get_web();

            this.webCollection = web.getSubwebsForCurrentUser(null);

            clientContext.load(this.webCollection);
            clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
        }
    }

    function onQuerySucceeded() {
        var webInfo = 'Child sites of the current site: \n\n';
        var webEnumerator = this.webCollection.getEnumerator();
        while (webEnumerator.moveNext()) {
            var web = webEnumerator.get_current();
            webInfo += web.get_title() + '\n';
        }
        alert(webInfo);
    }

    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>

See Also

Reference

SP.Web Methods

SP.Web Properties

SP Namespace