最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to change Ext js store data dynamically - Stack Overflow

programmeradmin2浏览0评论

I have a combobox which looks like below

{
  xtype:'combo',
  fieldLabel:'Test',
  store:['a','b']
}

Without creating Ext store object I am assigning the array to store and it is displaying the values fine.

At some action i want to update the store with ['d','e']

I have tried by assigning the new values to store like below

comboObje.store=['d','e'];

but it is not updating the values.

how to replace the orginal values with new values in the store.

I have a combobox which looks like below

{
  xtype:'combo',
  fieldLabel:'Test',
  store:['a','b']
}

Without creating Ext store object I am assigning the array to store and it is displaying the values fine.

At some action i want to update the store with ['d','e']

I have tried by assigning the new values to store like below

comboObje.store=['d','e'];

but it is not updating the values.

how to replace the orginal values with new values in the store.

Share Improve this question asked Sep 3, 2015 at 16:49 Surya Prakash TummaSurya Prakash Tumma 2,1934 gold badges28 silver badges50 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 9

You can create a new store using bindStore or just load new data to the existing store using loadData:

combo.store.loadData(['d', 'e'].map(function(item){ return [item]; }));

Working example: https://fiddle.sencha.com/#fiddle/tb1

In version 5.* and higher you can use:

comboObje.setStore(['d','e']);

This doesn't work in previous versions.

Paste the following code into a Sencha Fiddle as a 'proof-of-concept':

Ext.application({
    name : 'Fiddle',

    launch : function() {
        var panel = Ext.create('Ext.form.Panel', {
            title: 'test',
            items: [{
                xtype:'combo',
                fieldLabel:'Test',
                store:['a','b']
            }],
            renderTo: Ext.getBody()
        });

        panel.down('combo').setStore(['d','e']);
    }
});

Try this:

comboObje.getStore().loadData([{'field1': 'd'}, {'field1': 'e'}]);

When you assign an array to 'store' config, ExtJS automatically generates field names.

发布评论

评论列表(0)

  1. 暂无评论