I have a question regarding the ajax
callback
function
I have
test = function(){
this.items=[];
}
//original state.
test.prototype.getListItems = function (){
this.items.push('test item');
this.handleItems();
}
//this method will be called if the user clicks a button.
test.prototype.clickBtn = function (){
this.ajGetOneMoreItem()
this.handleItems();
}
//a callback function that will add a new item.
test.prototype.ajGetOneMoreItem = function (){
var that=this;
ajax.callback = function(dataItem){
that.items.push(dataItem);
}
}
//to show the items.
test.prototype.handleItems = function (){
//only show the test item, but not dataItem after user clicks a button.
console(this.items)
}
var testObj = new test();
$('#testBtn).click(function(){
testObj.clickBtn();
})
I want to show the new items that was added through the user.
However, it only appears this.items only show the first 'test item
' but did not add the new dataItem
. Am I missing something here? Thanks a lot!