0

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

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

4

2 回答 2

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());

});

}

于 2013-03-20T22:59:02.723 回答
0

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

以下示例演示如何将全局导航设置为显示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();    
});
于 2014-12-02T23:12:49.707 回答