[英]How do I set the value of a URL field in the SharePoint 2013 JSOM
有人知道如何在SharePoint 2013 JSOM中設置URL字段的描述和url嗎? 我見過的所有字段設置示例都使用spListItem.set_item(fieldName,fieldValue)
,它適用於諸如文本或數字之類的簡單字段,但是對於復雜的URL字段類型,我卻失敗了。 我嘗試傳遞我的URL字段名和逗號分隔的fieldValue = "descriptionText,url"
我還嘗試了SP.ListItem.parseAndSetFieldValue(fieldname,fieldValue)
,傳入URL字段名和逗號分隔的fieldValue = "descriptionText,url"
。
我在這里缺少簡單的東西嗎?
使用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); }
這是有關如何在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)
);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.