I have to get an argument value from the function inside the onlick
property of a button, but the function (this.getListItemId(itemId)
) which makes use of this argument is not inside of the context from where the button is. The button is inside a child function
(this.renderVideoListTemplate()
) which is inside a parent function (getVideoListItems()
). The function i want call on the onclick event (this.getListItemId()
) it is outside from where the function of the button (this.renderVideoListTemplate()
) is, so it says the function (this.getListItemId(itemId)
) does not exists.
var getVideoListItems = function() {
var self = this;
this.renderVideoListTemplate = function(result) {
for(let i=0; i < result.length; i++){
====>>> var listItems ="<div class='Button fecharVideo' onclick='"+self.getListItemId(result[i].ID)+"'>"+
"<span class='Button'>Excluir Vídeo</span>"+
"</div>";
$("#video-list-container").append(listItems);
};
};
this.deleteListItem = function(webUrl, listName, itemId, success, failure) {
self.getDataByItemId(webUrl,listName,itemId,function(item){
$.ajax({
url: item.__metadata.uri,
type: "POST",
headers: {
"Accept": "application/json;odata=verbose",
"X-Http-Method": "DELETE",
"If-Match": item.__metadata.etag
},
success: function (data) {
success();
},
error: function (data) {
failure(data.responseJSON.error);
}
});
},
function (error) {
failure(error);
});
};
this.getListItemId = function(itemId){
self.deleteListItem(webUrl, listName, itemId)
};
return this.init();
}