这是我的代码
Ext.define('MyModel', {
extend: 'Ext.data.Model',
config: {
fields: ['name', {
name: 'twitter',
type: 'string'
}]
}
});
Ext.define('Fiddle.MyStore', {
extend: 'Ext.data.Store',
config: {
model: 'MyModel',
listeners: {
}
},
addrecords: function(store, records, eOpts) {
console.log('new recorded have been added.');
console.log('new recorded number = ' + store.getCount());
}
});
Ext.application({
name: 'Fiddle',
launch: function() {
Ext.Msg.alert('Fiddle', 'Welcome to Sencha Fiddle!');
var mystore = Ext.create('Ext.data.Store', {
data: [{
name: 'Mitchell Simoens',
twitter: 'SenchaMitch'
}, {
name: 'Jay Garcia',
twitter: 'ModusJeasus'
}, {
name: 'Anthony De Moss',
twitter: 'ademoss1'
}]
});
mystore.add({
name: "winston fan",
twitter: 'WFC'
});
//console.log('mystore has ' + mystore.getCount());
}
});
这是sencha小提琴: https://fiddle.sencha.com/#fiddle/6d1
我知道我可以使用mystore.on()绑定事件,但在我的情况下很难做到。所以我想将addrecords放入商店的配置中。但无论我把代码放在哪里
addrecords: function(store, records, eOpts) {
console.log('new recorded have been added.');
console.log('new recorded number = ' + store.getCount());
}
无论是在配置部分的监听器中,还是直接在商店下,addrecords事件都不会被触发。它仅在我使用mystore.on时触发(' addrecords',function(){});
有谁能告诉我如何将事件放入商店的配置中?
谢谢。答案 0 :(得分:-1)
商店配置中的事件是一个坏主意,因为它们可以轻松覆盖,但它们会进入侦听器。听众:{addrecords:function(){...}}
实际上,控制器应该使用store.on添加监听器(' addrecords',function ....)
(当然框架正在运行;你的代码坏了;-))