javascript SharePoint 2013 获取列表项字段值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21099980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SharePoint 2013 get list item field value
提问by Kate
I have a document library where I added a text column Read
. I'm using a script editor web part to insert some JavaScript. I need to get the value of this column Read
for a specific item (I know the item Id).
我有一个文档库,我在其中添加了一个文本列Read
。我正在使用脚本编辑器 Web 部件插入一些 JavaScript。我需要获取Read
特定项目的此列的值(我知道项目 Id)。
I would appreciate any help. Thank you!
我将不胜感激任何帮助。谢谢!
回答by Kate
This code worked:
此代码有效:
this.oListItem = oList.getItemById(itemid);
ctx.load(this.oListItem);
ctx.executeQueryAsync(Function.createDelegate(this,
function () {prevText = this.oListItem.get_item('Read'); }),
function (sender, args) { alert('Error occured' + args.get_message());
});
回答by MikeTran13
You should use Sharepoint client object model to get the document library where you added the text column. After that you can get the list item by building a caml query with the item id and you can get the value of your column.
您应该使用 Sharepoint 客户端对象模型来获取添加文本列的文档库。之后,您可以通过使用项目 id 构建一个 caml 查询来获取列表项,并且您可以获得列的值。
回答by AymKdn
You may want to use SPServicesor SharepointPlusto help you. With SharepointPlus the code would be:
您可能希望使用SPServices或SharepointPlus来帮助您。使用 SharepointPlus,代码将是:
$SP().list("Name of your list").get({fields:"Read",where:"ID = 123"}, function(data) {
if (data.length===1) alert("Read = "+data[0].getAttribute("Read"))
else alert("Unable to find ID 123")
})