老实说,我是Office 365开发的新手。
我想在点击页面中的按钮后,将现有内容类型添加到网站集中所有子网站的所有列表中。我将尝试使用通过JavaScript访问所有列表的沙盒解决方案,但我无法找到方法。
如果有人可以帮我解决这个问题,我将不胜感激。
答案 0 :(得分:0)
试试这段代码:
var contentTypeCollection;
var contentType;
var listCollection;
var list;
var listContentTypeColl;
function addExistingContentTypetoList() {
var clientContext = new SP.ClientContext.get_current();
if (clientContext != undefined && clientContext != null) {
var web = clientContext.get_web();
this.contentTypeCollection = web.get_contentTypes();
this.contentType = contentTypeCollection.getById("0x0100FFC434A461E47E4EB81D3FD76D42BFBF");
this.listCollection = web.get_lists();
this.list = listCollection.getByTitle("List Request");
this.listContentTypeColl = list.get_contentTypes();
this.listContentTypeColl.addExistingContentType(contentType);
clientContext.load(this.listContentTypeColl);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
}
function onQuerySucceeded() {
alert('Content Type added successfully');
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}