كيفية الحصول على جذر الاختلافات عن طريق العميل OM (JS)؟

sharepoint.stackexchange https://sharepoint.stackexchange.com//questions/88367

سؤال

دعونا أقول إن لدي مواقع فرعية على "موقعها الرئيسي" (الذي لا يسذر لجمع الموقع)، مثل موقع المنزل الفرعي، والاتصال."الموقع الرئيسي" هو في الواقع تباين لغة موقع آخر.في كلمات أخرى لدي هيكل مثل هذا giveacodicetagpre.

ما أرغب في فعله هو شيء ما يلي giveacodicetagpre.

تحرير: السؤال هو لشركة SharePoint 2013.

هل كانت مفيدة؟

المحلول

It actually depends what version of SharePoint is used.

How to retrieve Variation Labels via CSOM?

Since variations labels are stored in a Hidden List (MOSS 2007, SPS 2010/2013) we could retrieve it via CSOM (ECMAScript) as demonstrated below:

function getVaritationLabels(OnSuccess,OnError){
    var ctx = SP.ClientContext.get_current();
    var rootWeb = ctx.get_site().get_rootWeb();
    var webProperties = rootWeb.get_allProperties(); 
    ctx.load(rootWeb); 
    ctx.load(webProperties);
    ctx.executeQueryAsync(
      function() {
         var varLabelsListId = webProperties.get_item('_VarLabelsListId');

         var labelsList = rootWeb.get_lists().getById(varLabelsListId);
         var labelItems = labelsList.getItems(SP.CamlQuery.createAllItemsQuery());

         ctx.load(labelItems);
         ctx.executeQueryAsync(
            function() { 
               var variationLabels = [];

                var e = labelItems.getEnumerator();
                while (e.moveNext()) {
                    var labelItem = e.get_current();
                    variationLabels.push({
                        'IsSource': labelItem.get_item('Is_x0020_Source'),
                        'Language': labelItem.get_item('Language'),
                        'Locale': labelItem.get_item('Locale'),
                        'Title': labelItem.get_item('Title'),
                        'TopWebUrl': labelItem.get_item('Top_x0020_Web_x0020_URL')
                    });  
                }

               OnSuccess(variationLabels);
            },
            OnError
         );

      },
      OnError
    );
}

The function returns an array of Variation Label entries:

IsSource - Determines whether the Variation Label is set as the source label

Language - Returns the Language of the Variation Labe

Locale - Returns the Locale of the Variation Label

Title - Returns the title of the Variation Label, which is the unique string identifier of the label

TopWebUrl - Returns the URL of the top Publishing Web of the variation hierarchy of this label.

Example: How to determine Variation Home?

Assume the following variation labels have been configured

enter image description here

where

en-us Variation Label corresponds to Variation Home (Is Source parameter is set to True)

then the following function will return the Url of the variation hierarchy:

function getVariationLabelSourceUrl()
{
    var sourceUrl = '';
    getVaritationLabels(
      function(variationLabels){
          for(var j = 0; j < variationLabels.length;j++){
              var variationLabel = variationLabels[j];
              if(variationLabel.IsSource){
                  sourceUrl = variationLabel.TopWebUrl.get_url();
                  break;
              }
          }
          console.log('Variation Label Source Url: ' + sourceUrl);
      },
      function(sender,args) {
        console.log('An error occurred: ' + args.get_message());
      }
    );
}

P.S. The demonstrated code samples been tested with SharePoint 2013

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى sharepoint.stackexchange
scroll top