javascript 如何在 SharePoint 2013 JSOM 中设置 URL 字段的值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15503654/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I set the value of a URL field in the SharePoint 2013 JSOM
提问by Intranoggin
Anyone know how to set the description and url of a URL field in the SharePoint 2013 JSOM?
All the field settings examples I've seen use spListItem.set_item(fieldName,fieldValue)
which works great for simple fields like text or numbers, but it's failing for me on the complex URL field type.
I've tried passing in my URL field name and a comma separated fieldValue = "descriptionText,url"
任何人都知道如何在 SharePoint 2013 JSOM 中设置 URL 字段的描述和 URL?我见过的所有字段设置示例都spListItem.set_item(fieldName,fieldValue)
适用于文本或数字等简单字段,但在复杂的 URL 字段类型上却失败了。我试过传入我的 URL 字段名称和逗号分隔fieldValue = "descriptionText,url"
I've also tried SP.ListItem.parseAndSetFieldValue(fieldname,fieldValue)
, passing in the URL field name and the comma separated fieldValue = "descriptionText,url"
.
我也试过SP.ListItem.parseAndSetFieldValue(fieldname,fieldValue)
,传入 URL 字段名称和逗号分隔的fieldValue = "descriptionText,url"
.
Am I missing something simple here?
我在这里错过了一些简单的东西吗?
回答by TimTheEnchanter
Use the SP.FieldUrlValue object:
使用 SP.FieldUrlValue 对象:
function?updateListItem()?{ ????
var?currCtx?=?new?SP.ClientContext();????? ????
var?web?=?currCtx.get_web();????? ????
var?lists?=?web.get_lists(); ????
var?myList?=?lists.getByTitle("List1"); ????
myItem?=?myList.getItemById(3); ??
var urlValue = new ?SP.FieldUrlValue();
urlValue.set_url("http://www.example.com");
urlValue.set_description("test link");
myItem.set_item("TestURL",?urlValue); ????
myItem.update(); ?
????? currCtx.executeQueryAsync(onUpdateListSucceed,?onFail);? }
????? currCtx.executeQueryAsync(onUpdateListSucceed,?onFail);? }
回答by Ruslan Korkin
here is an example on how to create a new SP.ListItem using javascript in SharePoint 2013 (Hyperlink or Picture):
以下是有关如何在 SharePoint 2013(超链接或图片)中使用 javascript 创建新 SP.ListItem 的示例:
function createListItem() {
var clientContext = new SP.ClientContext(_spPageContextInfo.siteAbsoluteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('TestList');
var itemCreateInfo = new SP.ListItemCreationInformation();
this.oListItem = oList.addItem(itemCreateInfo);
var hyperLink = new SP.FieldUrlValue();
hyperLink.set_url("http://cnn.com");
hyperLink.set_description("CNN");
oListItem.set_item('PetkaHyperLink', hyperLink);
oListItem.update();
clientContext.load(oListItem);
clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed)
);
}
I got if from How to set any SP.Field Value with JSOM (Javascript) in Sharepoint 2013 to New SP.Listitem
我从How to set any SP.Field Value with JSOM (Javascript) in Sharepoint 2013 到 New SP.Listitem