I'm trying to delete a list item from a SharePoint library via JavaScript with ClientContext. Unfortunately I don't have access to the ID of the item that's why I use the Title and I can not delete the List Item. All the time I receive the following error on line with deleteObject:
Uncaught TypeError: undefined is not a function
To use a Title a provide a CamlQuery. If I try to delete it with the comment line everything works perfect, but like I wrote there is no access to the ID of the item.
Here is my code:
function deleteListItemSP(title){
var siteUrl = 'mylink';
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('Demo');
var query = new SP.CamlQuery();
query.set_viewXml("<Where><Eq><FieldRef Name=\"Title\"/><Value Type=\"Text\">" + Title+ "</Value></Eq></Where>");
var oListItem = oList.getItems(query);
//this.oListItem = oList.getItemById(4);
oListItem.deleteObject();
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
Any idea what's wrong?