如何将记录添加到Ext JS数据存储并查看更改

时间:2019-03-03 22:17:41

标签: extjs

我无法动态更新商店,也看不到商店中反映的那些更新。我正在尝试向商店添加一条记录,只是看到商店反映了更新。这是控制器方法:

testGridrefresh() {
    console.log("start testGridrefresh");

    const testmodel = new MyCustomer.model.Testmodel({  // Testmodel is the model used by my store

        firstName: 'joe',
        lastName: 'whatever'
    });
    console.log(testmodel);  // logs correctly, i can see the fields
    store = this.getStore('tests');
    console.log("count in store:");
    console.log(store.getTotalCount()); // i hard coded 2 items, prints 2
    store.add(testmodel);
    store.commitChanges();
    store.sync();
    store.reload();
    console.log("lets see what the count in store is now");
    console.log(store.getTotalCount()); // still logs 2

    // try different approach:
    var new_data = {
            'newrecord': {
                "firstName": 'joe',
                "lastName": 'whatever' 
            }
        };

    store.add(new_data);
    store.commitChanges();
    store.sync();
    store.reload();
    console.log("lets see what the count in store is now");
    console.log(store.getTotalCount()); // still logs 2

    }

0 个答案:

没有答案