我正在研究MVC模式。 我有两个功能,一个是工作,另一个是不工作。看看我的控制器代码;
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功能运行良好。但是当我修改该代码时,添加一个消息框确认,即使我定义了商店,代码也无法正常工作。
请您告诉我如何解决这个问题?
答案 0 :(得分:2)
您需要设置回调的范围:
Ext.Msg.confirm('A', 'B', function() {
}, this);
答案 1 :(得分:0)
您的商店实例仍然绑定到网格,所以只需执行以下操作:
viviewList.getStore().remove(selection)