gpt4 book ai didi

javascript - Sharepoint - 未捕获的类型错误 : Cannot set property 'newColumns' of undefined

转载 作者:行者123 更新时间:2023-11-30 16:37:30 26 4
gpt4 key购买 nike

我正在使用 Javascript 创建一个列表。但是在将列添加到列表时出现错误

function createlist() {
// Create a generic SharePoint list with the name that the user specifies.
var listCreationInfo = new SP.ListCreationInformation();
var listTitle = "MyList";
listCreationInfo.set_title(listTitle);
listCreationInfo.set_templateType(SP.ListTemplateType.genericList);
lists = web.get_lists();
var newList = lists.add(listCreationInfo);

var newCols = [ "<Field Name='PageText' DisplayName='Page Text' Type='Note' RichText='TRUE' RichTextMode='FullHtml' NumLines='10' />",
true];

var numberCols = newCols.length;
for (var i = 0; i < numberCols; i++) {
this.newColumns= newList.get_fields().addFieldAsXml(newCols[i],true,SP.AddFieldOptions.defaultValue);
}


context.load(numberCols);
context.executeQueryAsync(onListCreationSuccess, onListCreationFail);
}

Uncaught TypeError: Cannot set property 'newColumns' of undefined

createlist @ App.js:57

(anonymous function) @ App.js:18

b.Callbacks.c @ jquery-1.9.1.min.js:3

b.Callbacks.p.fireWith @ jquery-1.9.1.min.js:3

b.extend.ready @ jquery-1.9.1.min.js:3 H @ jquery-1.9.1.min.js:3

在我出错的地方帮助我

最佳答案

该示例包含一些错误/拼写错误:

  • SP.FieldCollection.addFieldAsXml 函数接受字段 xml(字符串类型)作为第一个参数,但您从 newCols 传递 bool 值(!) 数组

    SP.ClientContext.load 函数接受 SP.ClientObject 对象,但在行:context.load(numberCols); numberCols 是一个数值

修改示例

下面提供了您的示例的略微修改版本:

function createlist(listTitle,fieldDefs,success,error) {

var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var listCreationInfo = new SP.ListCreationInformation();
listCreationInfo.set_title(listTitle);
listCreationInfo.set_templateType(SP.ListTemplateType.genericList);
var list = web.get_lists().add(listCreationInfo);
var fields = [];
for (var i = 0; i < fieldDefs.length; i++) {
var field = list.get_fields().addFieldAsXml(fieldDefs[i],true,SP.AddFieldOptions.defaultValue);
fields.push(field);
ctx.load(field);
}
ctx.executeQueryAsync(
function(){
success(fields);
}, error);
}

用法

var listTitle = 'Requests';
var fieldDefs = [ "<Field Name='RequestDesc' DisplayName='Request Description' Type='Note' RichText='TRUE' RichTextMode='FullHtml' NumLines='10' />"];

createlist(listTitle,fieldDefs,
function(fields){
console.log('List has been created successfully');
},
function(sender,args)
{
console.log(args.get_message());
});

关于javascript - Sharepoint - 未捕获的类型错误 : Cannot set property 'newColumns' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32508314/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com