Reputation: 67
I am working on MVC Pattern. I have two function bellow, one is working and the other is not working. Take a look at my controller code;
Ext.define('MyApp.controller.program', {
extend: 'Ext.app.Controller',
stores: [
'program'
],
deleteWithConfirm: function(button, e, options) {
var viewList = Ext.ComponentQuery.query('#programGrid')[0];
var selection = viewList.getSelectionModel().getSelection()[0];
if(selection)
{
Ext.MessageBox.confirm('Confirm', 'Are you sure you want to do that?',
function(btn, text ) {
if(btn == 'yes') {
console.log('yes clicked');
this.getProgramStore().remove(selection); //console error message: "TypeError: this.getProgramStore is not a function"
this.getProgramStore().sync();
}
if(btn == 'no') {
console.log('no clicked');
}
}
);
}
},
justDelete: function(button, e, options) {
var viewList = Ext.ComponentQuery.query('#programGrid')[0];
var selection = viewList.getSelectionModel().getSelection()[0];
if(selection)
{
this.getProgramStore().remove(selection);
this.getProgramStore().sync();
}
},
init: function(application) {
this.control({
"#tombolHapusProgram": {
click: this.deleteWithConfirm //this is not working
//click: this.justDelete //this is working
}
});
}
});
justDelete function is working good. But when I modify that code, adding a message box confirm, the code is not working even though I defines store.
Would you please show me how to solve this problem?
Upvotes: 1
Views: 3007
Reputation: 30082
You need to set the scope for the callback:
Ext.Msg.confirm('A', 'B', function() {
}, this);
Upvotes: 2
Reputation: 15673
Your store instance is bound to the grid anyways so just do the following:
viviewList.getStore().remove(selection)
Upvotes: 0