[英]How to use the javascript getPeerUrl() function in Sharepoint 2013 client object model?
I want to use this function https://msdn.microsoft.com/en-us/library/office/jj954403.aspx to get the french url from the english url (I can't just simply change the en to fr and vice versa). 我想使用此功能https://msdn.microsoft.com/zh-cn/library/office/jj954403.aspx从英文url获取法语url(我不能只是简单地将en更改为fr,反之亦然反之亦然)。
But I am having trouble with the function. 但是我在功能上遇到了麻烦。 It seems to give me
0
instead of the actual url. 看来是给我
0
而不是实际的网址。
This is my code 这是我的代码
function VariationHandler2() {
var ctx = SP.ClientContext.get_current();
var site = ctx.get_site();
var rootWeb = site.get_rootWeb();
var webProperties = rootWeb.get_allProperties();
ctx.load(site);
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 url = rootWeb.get_serverRelativeUrl();
var object = SP.Publishing.Variations.getPeerUrl(ctx, "/en/Pages/default.aspx", "fr");
alert(object);
alert(object.get_value());
alert(JSON.stringify(object));
},
function() {
}
);
},
function() {
}
);
}
but I am not getting any useful results. 但我没有得到任何有用的结果。 Does anyone know how to get it to work?
有谁知道如何使它工作?
Thanks 谢谢
I added the following code to a Content Editor on a publishing page in a site with variations and it worked: 我将以下代码添加到具有变体的网站发布页面上的内容编辑器中,并且可以正常工作:
<script src="/_layouts/15/sp.publishing.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
ExecuteOrDelayUntilScriptLoaded(VariationHandler, "sp.js");
});
function VariationHandler() {
ExecuteOrDelayUntilScriptLoaded(VariationHandler2, "SP.publishing.js");
}
function VariationHandler2() {
var ctx = SP.ClientContext.get_current();
var object = SP.Publishing.Variations.getPeerUrl(ctx, "/en/Pages/default.aspx", "fr");
ctx.executeQueryAsync(
function() {
alert(object.get_value());
}
);
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.