如何使用REST更新SharePoint列表中的图像URL字段 [英] How to update an image url field in SharePoint list using REST

查看:80
本文介绍了如何使用REST更新SharePoint列表中的图像URL字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SharePoint列表(我们称它为雇员"),并且我正在使用jQuery和REST来读取和写入该列表上的属性.

I have a SharePoint list (let's call it 'Employee') and I am using jQuery and REST to read and write properties on that list.

如果我想更新例如一个int属性(我们称之为"EmployeeAge"),非常简单:

If I want to update e.g. an int property (let's call it 'EmployeeAge'), it's quite straightforward:

jQuery.ajax({
        url: myUrl,
        type: "POST",
        data:  JSON.stringify({ '__metadata': { 'type': 'SP.Data.EmployeeListItem' }, 'EmployeeAge': age }),
        headers: { 
            "accept": "application/json;odata=verbose",
            "content-type": "application/json;odata=verbose",
            "content-length": 0,
            "X-HTTP-Method": "MERGE",
            "X-RequestDigest": $("#__REQUESTDIGEST").val(),
            "IF-MATCH": "*"

        },

        success: successHandlerUpdateEmployeeAge,
        error: errorHandlerUpdateEmployeeAge
        });

现在,我想使用相同的原理来更新列表的另一列.我们称之为"EmployeeImage".该列的类型为超链接/图片",子类型为图片".我想为特定列表项设置列的图片网址属性.

Now I want to use the same principle to update another column of the list. Let's call it 'EmployeeImage'. The column is of type Hyperlink/Picture and sub type Picture. I want to set the image url attribute of the column for a particular list item.

如何在ajax调用中格式化数据属性以支持这种类型的更新?

How do I format the data attribute in my ajax call to support this type of update?

我可以找到上千个有关如何更新标题字段的示例,但是找不到关于此类复杂类型更新的示例.

I can find a thousand samples on how to update a title field, but none regarding update of complex types like this.

推荐答案

在更正列名问题后搜索了错误消息后,我找到了答案.结果实际上很简单:

After googling the error message I got after correcting the column name issue, I found the answer. It actually turned out to be quite simple:

为了更新这样的复杂类型,您需要将其提供为javascript对象,而不是:

In order to update a complex type like this, you need to provide it as a javascript object, instead of:

'EmployeeImage': 'http://myurl'

使用此表示法提供对象结构:

Use this notation to provide the object structure:

'EmployeeImage': {Url: 'http://myurl', Description: 'This is the description'}

看看这篇文章,它为我指明了正确的方向:[

Take a look at this article that pointed me in the right direction: [http://social.msdn.microsoft.com/Forums/sharepoint/en-US/a4b4bfcf-1758-4131-9af2-bd1ecf0c839b/not-able-to-insert-a-record-in-a-list-using-rest?forum=appsforsharepoint]

这篇关于如何使用REST更新SharePoint列表中的图像URL字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆