ExtJs:获取商店创建的商店数据(ExtJs: Get store data on store creation)

系统教程 行业动态 更新时间:2024-06-14 17:02:18
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(); } }, });

更多推荐

本文发布于:2023-04-21 19:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/68fd9ca317cd02f65a34b59f3aaadbaf.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:商店   数据   ExtJs   creation   data

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!