0

JavaScriptからCSOM(Client-Side Object Model)を利用して、SharePoint 2013のサイト設定→マスターページ・ナビゲーション設定などにアクセスしたい、Javascriptから呼び出せるRESTサービスやWebサービスを利用したい。そのような 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 クラスです。

次の例は、Global Navigation を display に設定する方法を示しています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 に答える