Ext 4.1.1: Add new record to Store

后端 未结 2 2036
余生分开走
余生分开走 2021-01-05 03:49

I would like to add records after the initialization of a store.

I tried loadData(), loadRawData(), add() but nothing seams to work.

Here is my jsfiddle: htt

相关标签:
2条回答
  • 2021-01-05 04:24

    You need to set queryMode: 'local' in the combo box. Minimal example:

    Ext.onReady(function() {
        var store = Ext.create('Ext.data.Store', {
            alias: 'store.ModeStore',
            autoLoad: false,
            fields: [{
                name: 'mode',
                type: 'string'
            }, {
                name: 'id',
                type: 'string'
            }],
            data: [{
                mode: 'mode1',
                id: 1
            }]
        });
    
        var container = Ext.create('Ext.form.field.ComboBox', {
            renderTo: Ext.getBody(),
            displayField: 'mode',
            valueField: 'mode',
            store: store,
            queryMode: 'local'
        });
    
        store.add({
            mode: 'mode2',
            id: 2
        });
    }); 
    
    0 讨论(0)
  • 2021-01-05 04:29

    For a panel you can add or remove items by remove() and add()

    var store = Ext.create('MyApp.store.Roles', {autoLoad: false});
    store.load(function(records, action, success) {
        if (success) {
            store.remove(store.findRecord('id', 50, 0, false, true, true));//exact match
            store.add({'id':110,'name':'Agent' });
        }
    });
    
    0 讨论(0)
提交回复
热议问题