1

任何人都知道如何在 SharePoint 2013 JSOM 中设置 URL 字段的描述和 url?我见过的所有字段设置示例都spListItem.set_item(fieldName,fieldValue)非常适用于文本或数字等简单字段,但在复杂的 URL 字段类型上对我来说却失败了。我尝试传入我的 URL 字段名称和逗号分隔fieldValue = "descriptionText,url"

我也试过SP.ListItem.parseAndSetFieldValue(fieldname,fieldValue),传入 URL 字段名称和逗号分隔fieldValue = "descriptionText,url"

我在这里错过了一些简单的东西吗?

4

2 回答 2

5

使用 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); }

于 2013-04-04T02:35:18.493 回答
1

以下是有关如何在 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)  
   );  
 }

我从How to set any SP.Field Value with JSOM (Javascript) in Sharepoint 2013 到 New SP.Listitem

于 2015-06-22T11:20:42.827 回答