ExtJs:获取商店创建的商店数据(ExtJs: Get store data on store creation)
我有一个内置的简单组合框内的在线商店。 该商店有一些默认的内联数据。 现在我正在寻找一个事件,一旦创建商店就会被解雇,并且此事件需要向我提供商店中的数据。
我试过这样的:
Ext.create('Ext.form.ComboBox', { fieldLabel: 'Choose', store: { autoLoad: true, fields: [ {name: 'name', type: 'string'} ], data : [ {"name":"TestName_A"}, {"name":"TestName_B"}, {"name":"TestName_C"}, ], listeners: { load: function(store) { let records = store.getData() records.forEach(record => { console.log(record.getField('name')) }) } } }, queryMode: 'local', valueField: 'name', displayField: 'name', renderTo: Ext.getBody() });但它不起作用。 store.getData()似乎不包含我的记录。
有我的小提琴: https ://fiddle.sencha.com/ ? fiddle = v7#fiddle/ 1h53
I have an in-line store that is inside of a simple combobox. This store has some default inline-data. Now I'm looking for an event that gets fired once the store is created and this event needs to supply me with the data that is in the store.
I tried it like this:
Ext.create('Ext.form.ComboBox', { fieldLabel: 'Choose', store: { autoLoad: true, fields: [ {name: 'name', type: 'string'} ], data : [ {"name":"TestName_A"}, {"name":"TestName_B"}, {"name":"TestName_C"}, ], listeners: { load: function(store) { let records = store.getData() records.forEach(record => { console.log(record.getField('name')) }) } } }, queryMode: 'local', valueField: 'name', displayField: 'name', renderTo: Ext.getBody() });But it doesn't work. store.getData() doesn't seem to contain my records.
There's my fiddle: https://fiddle.sencha.com/?fiddle=v7#fiddle/1h53
最满意答案
现在使用这个商店show console数据:
Ext.create('Ext.form.ComboBox', { fieldLabel: 'Choose', queryMode: 'local', valueField: 'name', displayField: 'name', renderTo: Ext.getBody(), listeners: { afterrender: function(me) { var store = Ext.create('Ext.data.Store', { //autoLoad: true, fields: [ {name: 'name', type: 'string'} ], data : [ {"name":"TestName_A"}, {"name":"TestName_B"}, {"name":"TestName_C"}, ], listeners: { datachanged : function(store) { Ext.each(store.data.items,function(rec){ console.log(rec.data.name); }); } } }); me.setStore(store); store.load(); } }, });Use this now store show console data:
Ext.create('Ext.form.ComboBox', { fieldLabel: 'Choose', queryMode: 'local', valueField: 'name', displayField: 'name', renderTo: Ext.getBody(), listeners: { afterrender: function(me) { var store = Ext.create('Ext.data.Store', { //autoLoad: true, fields: [ {name: 'name', type: 'string'} ], data : [ {"name":"TestName_A"}, {"name":"TestName_B"}, {"name":"TestName_C"}, ], listeners: { datachanged : function(store) { Ext.each(store.data.items,function(rec){ console.log(rec.data.name); }); } } }); me.setStore(store); store.load(); } }, });更多推荐
发布评论