admin管理员组文章数量:1401298
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).
I would appreciate any help. Thank you!
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).
I would appreciate any help. Thank you!
Share Improve this question edited Jul 8, 2014 at 0:39 JasonMArcher 15k22 gold badges59 silver badges53 bronze badges asked Jan 13, 2014 at 19:43 KateKate 1,4954 gold badges21 silver badges36 bronze badges4 Answers
Reset to default 2This 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());
});
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.
You may want to use SPServices or SharepointPlus to help you. With SharepointPlus the code would be:
$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")
})
Using SPServices and jQuery, you can reference those in your code:
<script type="text/javascript" src="jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="jquery.SPServices.min.js"></script>
Then get the fields of the current item using this code:
<script type="text/javascript">
$(document).ready(function() {
// Don't forget to replace the document library's name
// if it's not "Documents"...
getListItems('Documents',
function(items){
var e = items.getEnumerator();
while (e.moveNext()) {
var item = e.get_current();
//console.log(item.get_item('FileLeafRef')); //print File or Folder Name
//console.log(item.get_item('FileRef')); //print File or Folder Url
var read = item.get_item('Read');
alert('Read = ' + read);
}
},
function(sender,args){
console.log(args.get_message());
}
);
});
function getListItems(listTitle,success,error)
{
//alert('getting items');
var context = SP.ClientContext.get_current();
var list = context.get_web().get_lists().getByTitle(listTitle);
var items = list.getItems(SP.CamlQuery.createAllItemsQuery());
context.load(items);
context.executeQueryAsync(
function() {
success(items);
},
error
);
}
</script>
本文标签: javascriptSharePoint 2013 get list item field valueStack Overflow
版权声明:本文标题:javascript - SharePoint 2013 get list item field value - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744295930a2599341.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论