Ext 4.1.1: Add new record to Store

天大地大妈咪最大 提交于 2019-12-18 22:59:10

问题


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: http://jsfiddle.net/charlesbourasseau/zVvLc

Any ideas ?


回答1:


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
    });
}); 



回答2:


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' });
    }
});


来源:https://stackoverflow.com/questions/11561075/ext-4-1-1-add-new-record-to-store

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!