简体   繁体   中英

Sencha Touch add individual records to store

I have been fighting this one for a while. Seems so trivial, yet can't get it to go. I just want to create a store, then slowly populate it with records based on UI actions. (Push a button > add the data to the store, push the next button > add that data to the store etc...)

Whenever I try to add the new record (after the first one has been added), the previous record gets wiped out and my store only has 1 record at all times.

How to add new records to the store (at different times, continuously adding new separate records)?

preparePost: function(data){

    //data is an object that comes from a button config...

    var mod = Ext.define('App.model.PostAttendanceModel', {
        extend: 'Ext.data.Model',
        config: {
            identifier: {
                type: 'uuid'
            },
            fields:[
                'items'
            ]
        }
    });

    var createStore = Ext.create('Ext.data.Store', {
        model: mod,
        storeId:'PostAttendanceStore'
    });

    var getStore = Ext.getStore('PostAttendanceStore');

    var store = typeof createStore != "undefined" ? getStore : createStore;

    var items = {
            attendancereasonid: data.attendancereasonid,
            level: data.level,
            personid: data.personid
    };

    store.add(items);

    console.info(store);

    //it is always the last record added, without "previous" records!
}

For whatever reason, it didn't like when I created the model and store on the fly. So, I created the appropriate model and store files, put them in the proper MVC structure - and now the

 store.add(items)

method works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM