SP.Web.getSubwebsForCurrentUser Method (sp.js)
Returns the collection of child sites of the current site based on the specified query.
Applies to: apps for SharePoint | SharePoint Foundation 2013 | SharePoint Server 2013
SP.Web.getSubwebsForCurrentUser()
Parameters
query
Type: SP.SubwebQuerySpecifies which child sites to return.
Return value
Type: SP.WebCollection
The subsites.
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>
REST resource endpoint
See Web resource for more information.
Endpoint URI structure
http://<sitecollection>/<site>/_api/web/getSubwebsForCurrentUser(query)
HTTP requests
This resource supports the following HTTP commands:
- POST
POST syntax
POST http://<sitecollection>/<site>/_api/web/getSubwebsForCurrentUser(query)
Resource parameters
- query