I am trying to return a list when its updated by Jax call but its not working .
class ep_List {
constructor() {
this.urlForAjax = '';
this.dataList = [];
this.dataJson = '';
this.dataParams = {};
this.cardList = [];
}
getData(method, params, url) {
this.urlForAjax = url;
this.dataParams = params;
if (method == 'get')
this.callGetAjax();
else
this.callPostAjax();
}
callPostAjax() {
$.post(this.urlForAjax, this.dataParams, this.setList.bind(this));
}
callGetAjax() {
$.get(this.urlForAjax, this.setList.bind(this));
}
setList(res) {
this.dataList = res;
ajaxPromise = true;
}
getCardList() {
var that = this;
setTimeout(function() {
return this.cardList = createCardList(that.dataList);
}, 3000);
}
}
so right now in my getCardList
function I have added setTimeout
that is because if I tried to do without timeOut some thing like this
var listObj = new ep_List();
listObj.getData('get', '', url);
listObj.getCardList();
console.log(listObj.cardList);
I was getting empty list ;
I am new to OOPS in js , would be great if you guys could help
Thanks