Since SPContext.Current gets the context of the current HTTP request and SPContext.Current.ListItem returns the current list item, I assume you need similar functionality in JSOM.
In SharePoint, the _spPageContextInfo structure is available on every page on the client side, which to some extent can be considered an analogue of SPContext.Current . In particular, the following properties are displayed to determine the current list item:
pageListId - Gets the identifier of the current ListpageItemId - Gets the current list item id
How to get the current list item using JSOM
The following function demonstrates how to extract the current list item:
function getCurrentListItem(success, error) { var context = SP.ClientContext.get_current(); var web = context.get_web(); var currentList = web.get_lists().getById(_spPageContextInfo.pageListId); var currentListItem = currentList.getItemById(_spPageContextInfo.pageItemId); context.load(currentListItem); context.executeQueryAsync( function(){ success(currentListItem); }, error ); }
Using
getCurrentListItem( function(listItem) { var priority = listItem.get_item('Priority'); console.log(priority); }, function(sender,args){ console.log(args.get_message()); } );
source share