使用CSOM(客户端对象模型)访问SP2013站点设置 - >主页面/导航设置等

时间:2013-03-08 20:09:36

标签: sharepoint-2010 sharepoint-2013 csom

我想使用来自JavaScript或REST服务或Web服务的CSOM(客户端对象模型)访问SharePoint 2013站点设置→母版页/导航设置等,我可以从Javascript调用。如果此类API /对象可用于SharePoint 2013,我可以获取指针吗?

更具体一点:我想访问并将站点设置→导航(在外观和感觉下)→全局和当前导航更改为“结构导航”而不是“管理导航”。我想使用CSOM(Javascript / REST / Web服务)实现这一目标。我不想使用服务器端对象模型。

2 个答案:

答案 0 :(得分:1)

设置母版页的完美工作脚本:

$(document).ready(function(){     jQuery('。cmdSet')。click(function(){

    var scriptBase = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/";

    $.getScript(scriptBase + "sp.runtime.js", function () {

        $.getScript(scriptBase + "sp.js", function () {

            $.getScript(scriptBase + "sp.core.js", sharePointReady);

        });
    });

});

});

// create page-level variables to hold client context and web
var context;
var web;
var masterurl;
var site;
function sharePointReady() {

// assign values to page-level variables
context = new SP.ClientContext.get_current();
web = context.get_web();

// provide CSOM with instructions to load info about current web


context.load(web, 'ServerRelativeUrl');
web.set_customMasterUrl(L_Menu_BaseUrl + '/_catalogs/masterpage/seattle.master');
web.set_masterUrl(L_Menu_BaseUrl + '/_catalogs/masterpage/seattle.master');
web.update();

context.executeQueryAsync(function () {

    alert("Starting Master Page Setting......");
    masterurl = web.get_serverRelativeUrl() + "/_catalogs/masterpage/seattle.master";
    alert(masterurl);
    alert("Master Page is Set Successfully!!!");

}, function (sender, args) {

    alert("Error: " + args.get_message());

});

}

答案 1 :(得分:0)

在SharePoint 2013中引入了新的SP.Publishing.Navigation命名空间(SharePoint Publishing JavaScript Library的一部分)。 特别是WebNavigationSettings class,用于管理发布网站的导航设置。

以下示例演示如何将全局导航设置为显示Structural Navigation

function configureNavigation()
{
   var ctx = SP.ClientContext.get_current();         
   var web = ctx.get_web();
   var webNavSettings = new SP.Publishing.Navigation.WebNavigationSettings(ctx,web);

   var navigation = webNavSettings.get_globalNavigation();
   navigation.set_source(SP.Publishing.Navigation.StandardNavigationSource.portalProvider); //set to Structural Navigation   
   webNavSettings.update();

   ctx.executeQueryAsync(
        function(){
            console.log("Navigation settings have been updated successfully");  
        },function(sender,args){    
            console.log(args.get_message());
        });
}

关键点:

用法

var scriptBase = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/";   
$.when(
    $.getScript( scriptBase + "sp.js" ),
    $.getScript( scriptBase + "sp.publishing.js" ),
    $.Deferred(function( deferred ){
        $( deferred.resolve );
    })
).done(function(){
     configureNavigation();    
});