2013-03-19 30 views
1

任何人都知道如何設置SharePoint 2013 JSOM中的URL字段的描述和url? 我見過的所有字段設置示例都使用spListItem.set_item(fieldName,fieldValue),它適用於諸如文本或數字等簡單字段,但對於複雜的URL字段類型而言,它失敗了。 我試圖傳遞我的URL字段名稱和逗號分隔fieldValue = "descriptionText,url"如何在SharePoint 2013 JSOM中設置URL字段的值

我也試過SP.ListItem.parseAndSetFieldValue(fieldname,fieldValue),通過在URL字段名稱和逗號分隔fieldValue = "descriptionText,url"

我在這裏錯過了一些簡單的東西嗎?

回答

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

0

這裏是如何創建在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 to New SP.Listitem

+1

哪裏差以前的解決方案? – 2015-06-22 12:12:27

相關問題