2013-03-19 49 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

相关问题