在控制器中设置存储事件的侦听器 [英] Set listener for store events in a controller
问题描述
我需要收听 beforesync
和在控制器中写入
存储的事件,但我不知道如何在控制器中设置这些监听器 control
-function。
我的商店看起来像这样:
Ext.define('DT.store.UsersStore',{
extends:'Ext.data.Store',
model:'DT.model.User',
id:' myStore'
autoSync:true,
proxy:{
type:'ajax',
api:{
read:'/ load_entries',
update :'/ update_entry'
},
reader:{
type:'json',
root:'user',
successProperty:'success'
}
}
});
现在我尝试听我的控制器中的事件:
...
init:function(){
this.control({
'myStore':{
beforesync:this.doSomething,
写:this.doSomethingElse
}
});
},
...
我的预期结果是,当事件被触发时被执行。
但是在这个时候,他们被解雇的时候什么都不会发生。
我该如何让这个工作?
您的方式是可行的,但它不是理想的,IMO。更好的方法是使用控制器的商店吸气剂。在你的情况下,代码将是这样的:
init:function(){
//每个控制器吸烟者为其商店。
//对于store UsersStore getter将是getUsersStoreStore()
this.getUsersStoreStore()。addListener('write',this.finishedLoading,this);
this.control({
// widgets event handlers
});
},
I have a controller with a store, a model, and some views.
I need to listen for the beforesync
and write
event of the store in the controller, but I don't know how to set these listeners in the controllers control
-function.
My store looks like this :
Ext.define('DT.store.UsersStore', {
extend : 'Ext.data.Store',
model : 'DT.model.User',
id : 'myStore'
autoSync : true,
proxy : {
type : 'ajax',
api : {
read : '/load_entries',
update : '/update_entry'
},
reader : {
type : 'json',
root : 'user',
successProperty : 'success'
}
}
});
Now I try to listen to the events in my controller :
...
init : function () {
this.control({
'myStore' : {
beforesync : this.doSomething,
write : this.doSomethingElse
}
});
},
...
My expected result is that the functions will be executed, when the events are fired. But at this time nothing happens when they are fired.
How can I get this to work?
Your way is possible but it's not ideal, IMO. The better way is to use controllers's store getter. In your case the code would be something like this:
init : function () {
// every controller has getters for its stores.
// For store UsersStore getter would be getUsersStoreStore()
this.getUsersStoreStore().addListener('write',this.finishedLoading, this);
this.control({
// widgets event handlers
});
},
这篇关于在控制器中设置存储事件的侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!