View Full Version : store.createModel() ??

22 Feb 2012, 10:52 PM
Looking in the source code (via the online docs).... I see in the store.js file a function called

createModel: function(record) {
if (!record.isModel) {
record = Ext.ModelManager.create(record, this.model);
} return record;

I don't see it mentioned elsewhere however.

It expects an object (record) to be passed as a parameter.
If you try store.createModel() with no argument...you get an error.
However, if you pass it anything (other than a record) it will return an empty instance of the store's model.

I'm trying it using

myNewRecord = myStore.createModel([]); and it seems to be working.

My store is configured like this:

Ext.define('CI.store.ContactPhoneNumbers', {
extend: 'Ext.data.Store',
model: 'CI.model.ContactPhoneNumber',
autoLoad: false

and it works pretty well as far as I can tell.

Any issues with using this function like this?

It gives me a method to create new models for a store, even if I don't know the model type expected by the store. For example I have a window which has 3 grids on it.

When the window opens, I want to add a blank record to each grid.

I can now loop through the grids and do this:

var grids = myWindow.query('grid');
Ext.Array.each(grids, function(grid){
newItem = grid.getStore().createModel([]);

Again, is this bad practice? and if so, why? A better way?

23 Feb 2012, 8:11 AM
Why not just use

foo : 'bar'

23 Feb 2012, 9:37 AM
Thanks Mitchell,

I was trying with store.add(); (no args)... .and it failed.

Of course using store.add({}) worked great. Thanks!